cap log close
log using "${log}/analysis_replication_appendix.log", replace
set more off
set matsize 800
version 14
set scheme s2color


/*************************************************************************\
|    Authors:         Hampole, Truffa, Wong		                          |
|    Date:            January 2026                                        |
|    Purpose:         Replication main analysis        					  |
\*************************************************************************/


* Appendix Figures
local p1 = 1 // Figure A1: Effect of Female Peers on Ever Holding Senior-Level Management Positions
local p2 = 1 // Figure A2: Effect of Female Peers on Job Characteristics of Senior Managers
local p3 = 1 // Figure A3: Effect of Female Peers on Job Characteristics
local p4 = 1 // Figure A4: Female Representation by Industry
local p5 = 1 // Figure A5: Probability of Holding a Senior-Level Management Position by Gender and Female-Friendly Firms
local p6 = 1 // Figure A6: Senior Manager in Female-Friendly Firms: Alternative Measures


* Appendix Tables
local p7 = 1 // Table A1: Summary Statistics by Job Title
local p8 = 1 // Table A2: Summary Statistics – Demographics and Pre-MBA Background + Summary Statistics – Demographics and Pre-MBA Background — Continued (REQUIRES ADMIN DATA)
local p9 = 1 // Table A3: Summary Statistics – Academic and Career Outcomes + Summary Statistics – Academic and Career Outcomes — Continued + Summary Statistics – Academic and Career Outcomes — Continued (REQUIRES ADMIN DATA)
local p10 = 1 // Table A4: Determinants of Likelihood of Holding a Senior Management Position
local p11 = 1 // Table A5: Gender Gap in Senior Management: Pooled Sample (Detailed Controls)
local p12 = 1 // Table A6: Section-Level Characteristics Correlated with Higher Proportion of Female Peers
local p13 = 1 // Table A7: Randomization Test - Female Pre-MBA Characteristics (Caeyers and Fafchamps, 2024) (REQUIRES ADMIN DATA)
local p14 = 1 // Table A8: Effect of Female Peers on Management Seniority Level, Employment, and Entrepreneurship
local p15 = 1 // Table A9: Effect of Female Peers on Dynamics in Senior Management Positions
local p16 = 1 // Table A10: Gender Differences in Total Compensation (Imputed)
local p17 = 1 // Table A11: Effect of Female Peers on Senior Management Controlling for Firm Size and Firm Average Compensation
local p18 = 1 // Table A12: Effect of Female Peers on Senior Manager in Female-Friendly Firms: Alternative Measures
local p19 = 1 // Table A13: Effect of Female Peers on GPA during MBA (REQUIRES ADMIN DATA)
local p20 = 1 // Table A14: Effect of Female Peers on Choice of Elective Classes (REQUIRES ADMIN DATA)
local p21 = 1 // Table A15: Effect of Female Peers on First Post-MBA Placement


* Appendix Section B
local p22 = 1 // Table B1: Coverage Rate of Alumni Directory, 2000-2010 Records
local p23 = 1 // Table B2: Coverage Rate of Alumni Directory Records by Class, 2000-2010
local p24 = 1 // Figure B1: Correlation Across Female-Friendliness Measures + Call code in R
local p25 = 1 // Figure B2: Female-Friendly Firms Representation by Industry
local p26 = 1 // Table B3: Female-Friendly Firms versus Non-Female-Friendly Firms
local p27 = 1 // Figure B3: Share of Senior Managers by Industry in the First Five Years Post-MBA
local p28 = 1 // Figure B4: Average Org Level by Management Level and Industry 
local p29 = 1 // Figure B5: Average Number of Direct Reports by Management Level and Industry 
local p30 = 1 // Figure B6: Average Number of Indirect Reports by Management Level and Industry 


* Appendix Section C
local p31 = 1 // Table C1: Gender Gap in Senior Management: Pooled Sample


* Appendix Section E
local p32 = 1 // Figure E1: Distribution of Residualized Actual and Simulated Female Share


* Appendix Section F
local p33 = 1 // Figure F1: Effect of Female Peers on Senior Management: Robustness Checks
local p34 = 1 // Figure F2: Effect of Female Peers on Holding Senior Management Positions Using Placebo Sections
local p35 = 1 // Table F1: Effect of Female Peers on Senior Management: Pre-MBA


* Appendix Section G
local p36 = 1 // Figure G1: Effect of Female Peers on Senior Management in Female-Friendly Firms by Component

* Appendix Section H
local p37 = 1 // Table H1: Survey Response Balance
local p38 = 1 // Figure H1: Composition of 10 Closest Professional Contacts
local p39 = 1 // Table H2: Effect of Female Peers on Peer Composition
local p40 = 1 // Table H3: Comparison of IHS Ratings and Female-Friendliness Measures from Survey Responses
local p41 = 1 // Figure H2: Work and Career Choices Due to Children
local p42 = 1 // Figure H3: Adverse Effects at Work Due to Children
local p43 = 1 // Figure H4: Effects of Female Peers on the Work Impacts of Children
local p44 = 1 // Table H4: Effect of Female Peers on Ambition and Self-Confidence
local p45 = 1 // Table H5: Effect of Female Peers on Negotiation
local p46 = 1 // Table H6: Effect of Female Peers on Nonemployment and Career Breaks
local p47 = 1 // Figure H5: Probability of Having Children
local p48 = 1 // Table H7: Effect of Female Peers on Marriage and Fertility
local p49 = 1 // Table H8: Effect of Female Peers on Career Satisfaction


adopath + "${code}"




* Figure A1: Effect of Female Peers on Ever Holding Senior-Level Management Positions
if `p1'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	


	
keep if year_since_grad>=1 & year_since_grad<=15

sort linkedin_id year_since_grad


preserve
bys section_id:keep if _n==1
sum femaleshare,d
restore
local p25 = r(p25)
local p75 = r(p75)
local p1 = r(p1)
local p99 = r(p99)
local p10 = r(p10)
local p90 = r(p90)

eststo clear
matrix results1 = J(15,3,.)
matrix results2 = J(15,3,.)
matrix results3 = J(15,3,.)
matrix coln results1 = b ll95 ul95 
matrix rown results1 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
matrix coln results2 = b ll95 ul95 
matrix rown results2 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
matrix coln results3 = b ll95 ul95 
matrix rown results3 = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
	
foreach x in ever_mgr2_v3   ///
			{

		
	eststo clear
	forval i =1/15{
		 
		 
		 eststo `x'_`i': reg `x' femaleshare_male femaleshare_female i.female  ///
			 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 if year_since_grad==`i', cluster(section_id)
		 
		sum `x' if year_since_grad==`i' & female==1, d
		local mean_f = r(mean)
		sum `x' if year_since_grad==`i' & female==0, d
		local mean_m = r(mean)
		
		sum `x' if year_since_grad==`i', d
		local mean = r(mean)
		local sd = r(sd)
		test femaleshare_male = femaleshare_female
		local p_value = r(p)
		eststo `x'_`i', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
		local var 1.female
		cap matrix results1[`i',1] = _b[`var'], _b[`var'] - 1.96*_se[`var'], _b[`var'] + 1.96*_se[`var']
		local var c.femaleshare_female
		cap matrix results2[`i',1] = _b[`var'], _b[`var'] - 1.96*_se[`var'], _b[`var'] + 1.96*_se[`var']
		local var c.femaleshare_male
		cap matrix results3[`i',1] = _b[`var'], _b[`var'] - 1.96*_se[`var'], _b[`var'] + 1.96*_se[`var']
		
		
	
	}
	

	
	coefplot (matrix(results2[,1]), ci((results2[,2] results2[,3])) label("Female share x Female")) ///
	(matrix(results3[,1]), ci((results3[,2] results3[,3])) label("Female share x Male") mcolor(navy*.30) ciopts(color(navy*.30)) ) ///
	 ,  ytitle("") yline(0) ///
	 base omitted ciopts(recast(rcap)) vertical ///
	 xtitle("Years since MBA graduation")  ///
	 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) ///
	 legend(rows(1))
	 graph export "${output}/graphs/Figure_A1.png",replace
	 
}
}

* Figure A2: Effect of Female Peers on Job Characteristics of Senior Managers
if `p2'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)

rename gd_totalpay gd_totpay
rename gd_totalpaysenior_manager gd_totpaysr_mgr

preserve
bys firm_id_LI: keep if _n==1
foreach var in gd_totpay gd_totpaysr_mgr{
	sum `var' [aweight=gd_reviews], d
	gen `var'_med = (`var'>=`r(p50)')
	replace `var'_med = . if `var'==.
	gen `var'_nomed = 1-`var'_med
}
keep firm_id_LI gd_totpay* gd_totpaysr_mgr*
tempfile median
save `median', replace 
restore

merge m:1 firm_id_LI using `median'
drop _merge


local fam_vars  small medium big ///
				i_fin i_cons i_good i_hlth i_tech i_oth ///
				gd_totpay_med gd_totpaysr_mgr_med gd_totpay_nomed gd_totpaysr_mgr_nomed

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

gen log_gd_i_totalpay = ln(gd_i_totalpay+1)
gen log_gd_i_bonuspay = ln(gd_i_bonuspay+1)
gen log_gd_i_basepay = ln(gd_i_basepay+1)

replace gd_i_basepay = gd_i_basepay/1000
replace gd_i_bonuspay = gd_i_bonuspay/1000
replace gd_i_totalpay = gd_i_totalpay/1000

preserve
collapse femaleshare_ind = female , by(i_categorical)
keep i_categorical femaleshare_ind
tempfile femaleshare_ind
save `femaleshare_ind', replace
restore

merge m:1 i_categorical using `femaleshare_ind'
drop _merge



matrix results = J(6,3,.)
matrix coln results = b ll95 ul95 
local i =1 

matrix results_ind = J(6,3,.)
matrix coln results_ind = b ll95 ul95 
local k =1 
*POOLED REGRESSIONS
foreach x in small_mgr medium_mgr big_mgr PL2_mgr2_v3 ///
	i_male_mgr2_v3 i_female_mgr2_v3 i_fin_mgr i_cons_mgr i_good_mgr i_hlth_mgr i_tech_mgr i_oth_mgr{
		
		if "`x'" == "gd_totpay_med_mgr" | "`x'" == "gd_totpay_nomed_mgr" {
			
		eststo `x': quietly reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean) 
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
		}
		else{
			eststo `x': quietly reg `x' femaleshare_male ///
			femaleshare_female i.female ///
			 i.Class##i.year_since_grad##i.female ///
				 i.top20##i.female ///
				 i.top20_m##i.female ///
				 pre_mgr2_v3##i.female  ///
				 pre_mgr2_v3_m##i.female  ///
				 c.pre_i_fin##i.female ///
				 i.pre_i_fin_m##i.female ///
				 c.m_pre_any_mgr_v3 ///
				 c.m_pre_mgr2_v3 ///
				 c.m_pre_i_fin ///
				 c.m_pre_i_cons ///
				 c.m_pre_i_oth ///
				 c.m_pre_PL2 ///
				 c.m_white ///
				 c.m_foreign ///
			 , cluster(section_id)
				
				sum `x' if female==1, d
				local mean_f = r(mean)
				sum `x' if female==0, d
				local mean_m = r(mean)
				
				sum `x', d
				local mean = r(mean)
				local sd = r(sd)
				test femaleshare_male = femaleshare_female
				local p_value = r(p)
				eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
				estadd local classfe "Yes" , replace


		}
		if inlist("`x'","i_fin_mgr", "i_cons_mgr", "i_good_mgr", "i_hlth_mgr" , "i_tech_mgr", "i_oth_mgr"){
			est restore `x'
			matrix results_ind[`k',1] = _b[femaleshare_female], _b[femaleshare_female] -1.96*_se[femaleshare_female], _b[femaleshare_female] +1.96*_se[femaleshare_female]
			local k = `k' + 1
		}
		else{
			est restore `x'
			matrix results[`i',1] = _b[femaleshare_female], _b[femaleshare_female] -1.96*_se[femaleshare_female], _b[femaleshare_female] +1.96*_se[femaleshare_female]
			local i = `i' + 1
		}

}


coefplot ///
	(matrix(results[,1]), ci((results[,2] results[,3])) rename(r1= "Less than 200 Employees" r2 = "200 to 4,999 Employees" r3 = "More than 5,000 Employees" r4 = "P & L Functions" r5 = "Male-Dominated Industries" ///
	 r6 = "Female-Dominated Industries" 	 ) offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) , ///
	 ytitle("") xline(0) ylabel(,labsize(small)) ///
	 base omitted headings("Less than 200 Employees" = "A. Firm Size" ///
	 "P & L Functions" = "B. Job Function" "Male-Dominated Industries" = "C. Industry")  ///
	 graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) legend(rows(1))
	 graph export "${output}/graphs/Figure_A2.png", replace


}

* Figure A3: Effect of Female Peers on Job Characteristics
if `p3'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

gen log_gd_i_totalpay = ln(gd_i_totalpay+1)
gen log_gd_i_bonuspay = ln(gd_i_bonuspay+1)
gen log_gd_i_basepay = ln(gd_i_basepay+1)

replace gd_i_basepay = gd_i_basepay/1000
replace gd_i_bonuspay = gd_i_bonuspay/1000
replace gd_i_totalpay = gd_i_totalpay/1000

preserve
collapse femaleshare_ind = female , by(i_categorical)
keep i_categorical femaleshare_ind
tempfile femaleshare_ind
save `femaleshare_ind', replace
restore

merge m:1 i_categorical using `femaleshare_ind'
drop _merge

egen size_LI_std = std(size_LI)
egen gd_totalpay_std = std(gd_totalpay)
egen gd_totalpaymgr_std = std(gd_totalpaysenior_manager)

matrix results = J(7,3,.)
matrix coln results = b ll95 ul95 
local i =1 

matrix results_ind = J(6,3,.)
matrix coln results_ind = b ll95 ul95 
local k =1 

*POOLED REGRESSIONS
foreach x in size_LI_std small medium big PL2 i_male i_female i_fin i_cons i_good i_hlth i_tech i_oth{
		
		if "`x'" == "gd_totalpay_std" | "`x'" == "gd_totalpaymgr_std" {
			
		eststo `x': quietly reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean) 
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
		}
		else{
			eststo `x': quietly reg `x' femaleshare_male ///
			femaleshare_female i.female ///
			 i.Class##i.year_since_grad##i.female ///
				 i.top20##i.female ///
				 i.top20_m##i.female ///
				 pre_mgr2_v3##i.female  ///
				 pre_mgr2_v3_m##i.female  ///
				 c.pre_i_fin##i.female ///
				 i.pre_i_fin_m##i.female ///
				 c.m_pre_any_mgr_v3 ///
				 c.m_pre_mgr2_v3 ///
				 c.m_pre_i_fin ///
				 c.m_pre_i_cons ///
				 c.m_pre_i_oth ///
				 c.m_pre_PL2 ///
				 c.m_white ///
				 c.m_foreign ///
			 , cluster(section_id)
				
				sum `x' if female==1, d
				local mean_f = r(mean)
				sum `x' if female==0, d
				local mean_m = r(mean)
				
				sum `x', d
				local mean = r(mean)
				local sd = r(sd)
				test femaleshare_male = femaleshare_female
				local p_value = r(p)
				eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
				estadd local classfe "Yes" , replace


		}
		if inlist("`x'","i_fin", "i_cons", "i_good", "i_hlth", "i_tech", "i_oth")==1{
			est restore `x'
			matrix results_ind[`k',1] = _b[femaleshare_female], _b[femaleshare_female] -1.96*_se[femaleshare_female], _b[femaleshare_female] +1.96*_se[femaleshare_female]
			local k = `k' + 1
		}
		else{
			est restore `x'
			matrix results[`i',1] = _b[femaleshare_female], _b[femaleshare_female] -1.96*_se[femaleshare_female], _b[femaleshare_female] +1.96*_se[femaleshare_female]
			local i = `i' + 1
		}

}

coefplot ///
	(matrix(results[,1]), ci((results[,2] results[,3])) rename(r1="Number of Employees (Std.)" r2 = "Less than 200 Employees" r3 = "200 to 4,999 Employees" r4 = "More than 5,000 Employees"  r5= "P & L Functions" r6 = "Male-Dominated Industries" ///
	 r7 = "Female-Dominated Industries" r8 = "Finance" ///
	 r9 = "Consulting" r10 = "Consumer Goods" r11 = "Healthcare" r12 =  "Technology" r13 = "Other" ) offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) , ///
	 ytitle("") xline(0) ylabel(,labsize(small)) ///
	 base omitted headings("Number of Employees (Std.)" = "A. Firm Size"  ///
	 "P & L Functions" = "B. Job Function" "Male-Dominated Industries" = "C. Industry")  ///
	 graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) legend(rows(1))
	 graph export "${output}/graphs/Figure_A3.png", replace
	 
	
}

* Figure A4: Female Representation by Industry
if `p4'==1{

use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear

keep if year_since_grad>=1 & year_since_grad <=15

sum female
local mean = r(mean)

gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

collapse female , by(i_categorical)

graph bar (asis) female ,  over(i_categorical, sort(1) descending relabel(1 "Finance" 2 "Consulting" 3 "Cons. Goods" 4 "Healthcare" 5 "Tech" 6 "Other")) ///
 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) ///
 ytitle("Proportion of Females") bar(1,color("25 81 144"))
graph export "${output}/graphs/Figure_A4.png", replace		
	
}

* Figure A5: Probability of Holding a Senior-Level Management Position by Gender and Female-Friendly Firms
if `p5'==1{
	
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear

local lastyear = 15

local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	
gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)


collapse mgr2_v3, by(female ihs_stars_med year_since_grad)

foreach y in mgr2_v3  {
	if "`y'"=="mgr2_v3"{
		local name "Probability of Senior-level Manager"
		local label ylabel(0(.1).6) 
		local elabel ylabel(0(.1).9)
	}
	

twoway (connected `y' year_since_grad if year_since_grad>=1 & year_since_grad<=`lastyear' & female==0 & ihs_stars_med==0, lcolor("216 240 243") mcolor("216 240 243") msymbol(oh)) ///
		(connected `y' year_since_grad if year_since_grad>=1 & year_since_grad<=`lastyear' & female==0 & ihs_stars_med==1, lcolor(edkblue*0.3) mcolor(edkblue*0.3) msymbol(T)) ///
		(connected `y' year_since_grad if year_since_grad>=1 & year_since_grad<=`lastyear' & female==1 & ihs_stars_med==0, lcolor("61 178 194") mcolor("61 178 194") msymbol(oh)) ///
		(connected `y' year_since_grad if year_since_grad>=1 & year_since_grad<=`lastyear' & female==1 & ihs_stars_med==1, lcolor(edkblue) mcolor(edkblue) msymbol(T)), ///
		plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) ///
		bgcolor(white) xlabel(1(1)`lastyear') ylabel(0(.2)1) legend(size(*0.8) rows(2) position(6) order(1 "Male: Non-Female-Friendly" 2 "Male: Female-Friendly" 3 "Female: Non-Female-Friendly" 4 "Female: Female-Friendly")) ///
		xtitle("Years since MBA graduation") ytitle("`name'")
		graph export "${output}/graphs/Figure_A5.png", replace

}
		
	
}

* Figure A6: Senior Manager in Female-Friendly Firms: Alternative Measures
if `p6'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay
gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
rename gd_fem_pct_d_totalpay gd_fem_d_tot
rename gd_sr_mgr_fem_pct_d_totalpay gd_mgr_fem_d_tot

preserve
bys firm_id_LI: keep if _n==1
foreach var in fgb_rating paid_weeks board_women_pct gd_fem_d_tot gd_mgr_fem_d_tot{
	
	if "`var'"=="paid_weeks" | "`var'"=="board_women_pct"{
	sum `var', d
	}
	if "`var'"=="fgb_rating"{
	sum `var' [aweight=fgb_reviews], d
	}
	if "`var'"=="gd_fem_d_tot" | "`var'"=="gd_mgr_fem_d_tot" {
	sum `var' [aweight=gd_reviews], d
	}
	gen `var'_med = (`var'>=`r(p50)')
	replace `var'_med = . if `var'==.
	replace `var'_med = 0 if employed == 0
	gen `var'_nomed = 1-`var'_med 
}
keep firm_id_LI fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med
tempfile median
save `median', replace 
restore

merge m:1 firm_id_LI using `median'
drop _merge


local fam_vars ihs_stars_med ihs_opportunities_med ihs_flexibility_med ihs_enrichment_med ihs_compensation_med ///
			ihs_family_med ihs_culture_med ///
			fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
	
	gen `var'_nomgr = (`var'==0 & mgr2_v3==1)
	replace `var'_nomgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge 

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

preserve	 
*COEFPLOT WITH INDICES
bys firm_id_LI: keep if _n==1



foreach x in size_LI ///
			gd_totalpay gd_totalpaysenior_manager ///
			gd_fem_pct_totpay gd_sr_mgr_fem_pct_totpay ///
			fgb_rating paid_weeks board_women_pct{
			
			egen z_`x' = std(`x')
}

gen weights = ihs_ratings_count + fgb_reviews

keep firm_id_LI z_size_LI top_100_firm ///
			z_gd_totalpay z_gd_totalpaysenior_manager ///
			z_gd_fem_pct_totpay z_gd_sr_mgr_fem_pct_totpay ///
			ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture  ///
			z_fgb_rating z_paid_weeks z_board_women_pct weights

tempfile firm_ihs
save `firm_ihs', replace 

restore

merge m:1 firm_id_LI using `firm_ihs'
drop _merge

rename z_gd_totalpaysenior_manager z_gd_totalpaysr_manager
rename z_gd_sr_mgr_fem_pct_totpay z_gd_sr_mgr_fem_pct_tot	 
	 
	 
*ALTERNATIVE MEASURE OF FEMALE FRIENDLINESS	
local j=1
foreach x in fgb_rating_med_mgr fgb_rating_med_nomgr ///
			paid_weeks_med_mgr paid_weeks_med_nomgr ///
			board_women_pct_med_mgr board_women_pct_med_nomgr ///
			{
			
		*MATRIX
		matrix results_`j' = J(1,3,.)
		matrix coln results_`j' = b ll95 ul95 
		matrix rown results_`j' = 1
		
		*POOLED REGRESSIONS
		
		if "`x'"=="fgb_rating_med_mgr" | "`x'"=="fgb_rating_med_nomgr"{
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=fgb_reviews], cluster(section_id)
		 
			sum `x' [aweight=fgb_reviews] if female==1, d
            local mean_f = r(mean)
            sum `x' [aweight=fgb_reviews] if female==0, d
            local mean_m = r(mean)
			
			sum `x' [aweight=fgb_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
			lincom femaleshare_female
			cap matrix results_`j'[1,1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		}
		
		if "`x'"=="paid_weeks_med_mgr" | "`x'"=="paid_weeks_med_nomgr" ///
		| "`x'"=="board_women_pct_med_mgr" | "`x'"=="board_women_pct_med_nomgr"{
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
			sum `x' if female==1, d
            local mean_f = r(mean)
            sum `x' if female==0, d
            local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
			lincom femaleshare_female
			cap matrix results_`j'[1,1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		}

		if "`x'"=="gd_fem_d_tot_med_mgr" | "`x'"=="gd_fem_d_tot_med_nomgr" ///
		| "`x'"=="gd_mgr_fem_d_tot_med_mgr" | "`x'"=="gd_mgr_fem_d_tot_med_nomgr" {
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
		 
			sum `x' [aweight=gd_reviews] if female==1, d
            local mean_f = r(mean)
            sum `x' [aweight=gd_reviews] if female==0, d
            local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
			lincom femaleshare_female
			cap matrix results_`j'[1,1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		}
	
		
				
		local j = `j'+1
		
}
	 
	 coefplot ///
	(matrix(results_1[,1]), ci((results_1[,2] results_1[,3])) rename(1="Female-Friendly Firm (FGB)") offset(0) label(Above Median) ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_2[,1]), ci((results_2[,2] results_2[,3])) rename(1="Female-Friendly Firm (FGB)") offset(-0.3) label(Below Median) ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_3[,1]), ci((results_3[,2] results_3[,3])) rename(1="Paid Maternity Leave") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_4[,1]), ci((results_4[,2] results_4[,3])) rename(1="Paid Maternity Leave") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_5[,1]), ci((results_5[,2] results_5[,3])) rename(1="% Female Board Members") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_6[,1]), ci((results_6[,2] results_6[,3])) rename(1="% Female Board Members") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)), ///
	 ytitle("") xlabel(-2(1)3) xscale(range(-2(1)3)) xline(0) ///
	 base omitted ///
	 note("Observations = `e(N)'") legend(position(6)) ///
	 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)  legend(rows(1))
	 graph export "${output}/graphs/Figure_A6.png",replace
	 


}

* Table A1: Summary Statistics by Job Title (Survey Data)
if `p7'==1{
use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"

* Define senior manager or higher
gen senior_manager_plus = 1 if top_manager_ever==1
replace senior_manager_plus = 0 if top_manager_ever==2

* Reg on senior manager 
reg senior_manager_plus femaleshare
areg senior_manager_plus femaleshare, ab(Class) 

* Define Year since graduation in which first management position
gen top_manager_first_yr_r =  2012 if top_manager_first_yr==13
	replace top_manager_first_yr_r = 2013 if top_manager_first_yr==14
	replace top_manager_first_yr_r = 2014 if top_manager_first_yr==15
	replace top_manager_first_yr_r = 2015 if top_manager_first_yr==16
	replace top_manager_first_yr_r = 2016 if top_manager_first_yr==17
	replace top_manager_first_yr_r = 2017 if top_manager_first_yr==18
	replace top_manager_first_yr_r = 2018 if top_manager_first_yr==19
	replace top_manager_first_yr_r = 2019 if top_manager_first_yr==20
	replace top_manager_first_yr_r = 2020 if top_manager_first_yr==21
	replace top_manager_first_yr_r = 2021 if top_manager_first_yr==22
	replace top_manager_first_yr_r = 2022 if top_manager_first_yr==23
	replace top_manager_first_yr_r = 2023 if top_manager_first_yr==24
	
* Impute year since graduation when first managerial position 
gen yr_since_gr_manager = top_manager_first_yr_r-Class 
	replace yr_since_gr_manager = . if missing(top_manager_first_yr_r) | missing(Class)

* Define if currently senior manager
gen senior_manager_plus_current = 1 if current_position==1 | current_position==2 | current_position==3 | current_position==4
	replace senior_manager_plus_current = 0 if missing(senior_manager_plus_current)
	replace senior_manager_plus_current = . if missing(current_position)
	

* Define Bonus Variables 
sum percent_bonus, detail
gen above_median_bonus = (percent_bonus>=25)
	replace above_median_bonus = . if missing(percent_bonus)

gen above_mean_bonus = (percent_bonus>=29)
	replace above_mean_bonus = . if missing(percent_bonus)

	
* Define Reports 
gen direct_reports = reports_4 
gen indirect_reports = reports_5

* Define P&L responsibilities 
gen p_and_l_dummy = (p_and_l==4) 
	replace p_and_l_dummy = . if missing(p_and_l) | p_and_l==6
	
gen femaleshare_abovemed = (femaleshare> 0.34)
replace femaleshare_abovemed=. if femaleshare==.


* Recode compensation
gen annual_income = .
replace annual_income = 125000 if compensation ==6
replace annual_income = 175000 if compensation ==7
replace annual_income = 250000 if compensation ==8
replace annual_income = 350000 if compensation ==9
replace annual_income = 450000 if compensation ==10
replace annual_income = 625000 if compensation ==11
replace annual_income = 875000 if compensation ==12
replace annual_income = 1000000 if compensation ==13

replace annual_income = . if compensation==3
 

/* SENIOR MANAGEMENT POSITION Validation */

* Fix senior manager variables
gen total_reports = reports_4 + reports_5

* Need to recode ladder
gen corporate_ladder = 1 if ladder==5
	replace corporate_ladder = 2 if ladder==4
	replace corporate_ladder = 3 if ladder==3
	replace corporate_ladder = 4 if ladder==2
	replace corporate_ladder = 5 if ladder==1



* Record current position
gen firm_role = 1 if current_position==5
	replace firm_role = 2 if current_position==4
	replace firm_role =3 if current_position==3
	replace firm_role =4 if current_position==2 | current_position==1
	//replace firm_role =5 if current_position==1
	
*hours worked (convert into continuous measure)
gen hours_week_c = 10 if hours_week ==1
replace hours_week_c = 25 if hours_week ==2
replace hours_week_c = 35 if hours_week ==3
replace hours_week_c = 45 if hours_week ==4
replace hours_week_c = 55 if hours_week ==5
replace hours_week_c = 65 if hours_week ==6
replace hours_week_c = 75 if hours_week ==7
replace hours_week_c = 85 if hours_week ==8


lab var total_reports "Total Reports"
lab var reports_4 "Direct Reports"
lab var reports_5 "Indirect Reports"
lab var corporate_ladder "Firm Hierarchy (1=Lowest, 5=Highest)"
lab var hours_week_c "Weekly Hours"
lab var annual_income "Total Compensation"


local variables total_reports reports_4 reports_5 corporate_ladder hours_week_c annual_income

forval i = 1/4{
	estpost sum `variables' if firm_role==`i'
	est store A`i'

}
esttab A1 A2 A3 A4  using "${output}/tables/Table_A1.tex", replace cells(mean(fmt(2) star) sd(par))  stats(N,fmt(%9.0fc)) star(* .10 * .05 ** .01)  ///
  label noobs collabels(none) booktabs f wide mtitles("Individual Cont" "Manager" "VP/Director" "SVP/C-Level") 
}

* Table A2: Summary Statistics – Demographics and Pre-MBA Background + Summary Statistics – Demographics and Pre-MBA Background — Continued
if `p8'==1{
*--------------------*
* Summary Statistics *
*--------------------*
use "${data}/raw/analysis_sections_fake.dta", clear

* Demographics
lab var approx_age "Age"
gen UScitizen = citizenship == 12
replace UScitizen = . if citizenship ==.
lab var UScitizen "U.S. Citizen"

gen race_1 = race==6
gen race_2 = race==1
gen race_3 = race==2 | race==3
gen race_4 = race==5
forval i = 1/4{
	replace race_`i' = . if race==4 | race==.
}

lab var race_1 "\quad White"
lab var race_2 "\quad Asian"
lab var race_3 "\quad Black / Hispanic"
lab var race_4 "\quad Other"

lab var GMAT "GMAT"

bys MasterPersonID: keep if _n==1
local demog approx_age UScitizen race_1 race_2 race_3 race_4 
rename female_dummy female
keep MasterPersonID  female `demog' GMAT
tempfile admin_data
save `admin_data'


// Linkedin data 
*Pre-MBA Background
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
//keep if Class<=2015

bys linkedin_id: keep if _n==1

lab var pre_exp "Pre-MBA Years of Experience"
lab var pre_any_mgr_v3 "Any Management Experience" 
lab var pre_mgr2_v3 "Any Senior-Level Management Experience"
lab var pre_gd_i_totalpay "Average Total Compensation (Imp.) ('000s)"

lab var pre_i_fin "\quad Finance"
lab var pre_i_cons "\quad Consulting"
lab var pre_i_good "\quad Consumer Goods"
lab var pre_i_hlth "\quad  Healthcare"
lab var pre_i_tech "\quad  Tech"
lab var pre_i_oth "\quad  Other Industries"
gen pre_i_male = pre_i_fin ==1 | pre_i_cons==1 | pre_i_tech==1
replace pre_i_male = . if pre_i_fin==. & pre_i_cons==. & pre_i_tech==. & pre_i_good==. & pre_i_hlth==. & pre_i_oth==.
lab var pre_i_male "Worked in Male-Dominated Industry"
lab var pre_size_LI "Firm Size"
lab var pre_top_100_firm "Worked in Top 100 MBA Firm"
lab var pre_ihs_stars_med "Worked in Female-Friendly Firm"
lab var pre_gd_totalpay "Average Firm Total Compensation ('000s)"
lab var pre_gd_fem_pct_d_totalpay "Average Gender Gap in Firm Total Compensation (\%)"
lab var pre_PL2 "Worked in P\&L Role"
lab var top20 "Top-20 Undergrad"

keep linkedin_id female pre_exp pre_any_mgr_v3 pre_mgr2_v3 pre_gd_i_totalpay pre_i_male top20 pre_gd_totalpay pre_gd_fem_pct_d_totalpay pre_size_LI pre_top_100_firm pre_ihs_stars_med pre_PL2   



foreach x in pre_gd_i_totalpay pre_gd_totalpay {
	replace `x' = `x'/1000
}

local pre_MBA GMAT pre_exp pre_any_mgr_v3 pre_mgr2_v3 pre_gd_i_totalpay pre_i_male top20 

append using `admin_data'

lab var female "Female"

*summary stats table
eststo clear
estpost sum female `demog'
est store A

estpost sum `demog' if female==0
est store B

estpost sum `demog'  if female==1
est store C

estpost ttest `demog', by(female) 
est store D

estadd matrix mean = e(b)
estadd matrix sd = e(p)

matrix list e(p)



esttab A B C D using "${output}/tables/Table_A2a.tex", replace ///
cells(mean(fmt(2) star) sd(par) count(par("N=") fmt(0))) ///
star(* .10 * .05 ** .01) label nonum collabels(none) booktabs f wide ///
mtitles("All" "Male" "Female"  "\shortstack{Difference \\ p-value in par.}") ///
refcat(female "\textbf{A. Demographics}" race_1 "Race", nolabel) noobs


*summary stats table
eststo clear
estpost sum `pre_MBA'
est store A

estpost sum  `pre_MBA' if female==0
est store B

estpost sum  `pre_MBA'  if female==1
est store C

estpost ttest  `pre_MBA', by(female) 
est store D

estadd matrix mean = e(b)
estadd matrix sd = e(p)


esttab A B C D using "${output}/tables/Table_A2b.tex", replace ///
cells(mean(fmt(2) star) sd(par) count(par("N=") fmt(0))) ///
star(* .10 * .05 ** .01) label nonum collabels(none) booktabs f wide ///
mtitles("All" "Male" "Female"  "\shortstack{Difference \\ p-value in par.}") ///
refcat(GMAT "\textbf{B. Pre-MBA Background}" pre_i_fin "Pre-MBA Industry", nolabel) noobs
 
}

* Table A3: Summary Statistics – Academic and Career Outcomes + Summary Statistics – Academic and Career Outcomes — Continued + Summary Statistics – Academic and Career Outcomes — Continued
if `p9'==1{
*--------------------*
* Summary Statistics *
*--------------------*
use "${data}/raw/analysis_sections_fake.dta", clear
** Academic and Career Outcomes 
rename female_dummy female

label var core_gpa "Overall Core GPA" 
label var gpa "Overall GPA" 
label var pct_noncore_finc "Fraction Elective Finance Classes"
label var pct_course_finc "Fraction Finance Classes"

local academics gpa core_gpa pct_course_finc 
keep MasterPersonID  female `academics' 
tempfile academic_data
save `academic_data',replace


//Linkedin
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear


keep if year_since_grad <=15 & year_since_grad>=1
gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)


rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay


lab var any_mgr_v3 "Any Management Role"
lab var mgr2_v3 "Senior-Level Manager"
lab var exp "Years of Experience"
lab var size_LI "Firm Size"
lab var posttenure_firm "Firm Tenure"
lab var employed "Employed"
lab var gap_total_c "Cumulative Months of Nonemployment"
lab var gd_i_totalpay "Total Compensation (Imp.) (000's)"
lab var gd_i_basepay "Base Compensation (Imp.) (000's)"
lab var gd_basepay "Average Firm Base Compensation (000's)" 
lab var gd_basepaysenior_manager "Average Firm Base Compensation for Senior Managers (000's)"
lab var gd_totalpay "Average Fiusrm Total Compensation (000's)"
lab var gd_totalpaysenior_manager "Average Firm Total Compensation for Senior Managers (000's)"
lab var	gd_fem_pct_totpay "Gender Gap in Firm Total Compensation (\%)"
lab var gd_sr_mgr_fem_pct_totpay "Gender Gap in Firm Total Compensation for Senior Managers (\%)"
lab var i_male "Male-Dominated Industry"
lab var ihs_stars_med "Female-Friendly Firm"
lab var top_100_firm "Top-100 MBA Firm"
lab var PL2 "P\&L Role"

foreach x in gd_i_totalpay gd_i_basepay gd_basepay gd_basepaysenior_manager gd_totalpay gd_totalpaysenior_manager{
	replace `x' = `x'/1000
}

append using `academic_data'

lab var female "Female"

local variables1 gpa core_gpa pct_course_finc any_mgr_v3 mgr2_v3 employed gap_total_c gd_i_basepay gd_i_totalpay i_male size_LI ihs_stars_med  PL2

	
	
*summary stats table
eststo clear
estpost sum  `variables1' 
est store A

estpost sum `variables1'  if female==0
est store B

estpost sum `variables1'  if female==1
est store C

estpost ttest `variables1' , by(female) 
est store D
estadd matrix mean = e(b)
estadd matrix sd = e(p)

esttab A B C D using "${output}/tables/Table_A3a.tex", replace cells(mean(fmt(2) star) sd(par) count(par("N=") fmt(0))) ///
  star(* .10 * .05 ** .01)  ///
 label nonum collabels(none) booktabs f wide mtitles("All" "Male" "Female" "\shortstack{Difference \\ p-value in par.}") ///
 refcat( gpa "\textbf{A. Academic Outcomes (Person Level)}" any_mgr_v3  "\textbf{B. Career Outcomes (Person-Year Level)}" , nolabel) noobs

 


use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear


keep if year_since_grad <=15 & year_since_grad>=1
gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)


rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

	
collapse (max) any_mgr_v3 mgr2_v3 employed gap_total_c i_male ihs_stars_med PL2  (sum) years_mgr_v3 = any_mgr_v3 years_mgr2_v3 = mgr2_v3 years_employed = employed years_i_male = i_male years_ihs_stars_med = ihs_stars_med years_PL2 = PL2 (mean)  gd_i_basepay gd_i_totalpay size_LI , by(linkedin_id female)

lab var any_mgr_v3 "Any Management"
lab var mgr2_v3 "Any Senior-Level Management"
lab var size_LI "Avg. Firm Size"
lab var employed "Any Employment"
lab var gap_total_c "Cumulative Months of Nonemployment"
lab var gd_i_totalpay "Avg. Total Compensation (Imp.) (000's)"
lab var gd_i_basepay "Avg. Base Compensation (Imp.) (000's)"
lab var i_male "Any Male-Dominated Industry"
lab var ihs_stars_med "Any Female-Friendly Firm"
lab var PL2 "Any P\&L Role"
lab var years_employed "Years in Employment"
lab var years_mgr_v3 "Years in Management"
lab var years_mgr2_v3 "Years in Senior-Level Management"
lab var employed "Years in Employment"
lab var years_i_male "Years in Male-Dominated Industry"
lab var years_ihs_stars_med "Years in Female-Friendly Firm"
lab var years_PL2 "Years in P\&L Role"


foreach x in gd_i_totalpay gd_i_basepay {
	replace `x' = `x'/1000
}



lab var female "Female"

local variables1  any_mgr_v3 years_mgr_v3 mgr2_v3 years_mgr2_v3 employed years_employed gap_total_c   gd_i_basepay gd_i_totalpay 
local variables2 i_male years_i_male size_LI ihs_stars_med years_ihs_stars_med PL2 years_PL2
	

 *summary stats table
eststo clear
estpost sum  `variables1'
est store A

estpost sum  `variables1' if female==0
est store B

estpost sum  `variables1' if female==1
est store C

estpost ttest `variables1', by(female) 
est store D
estadd matrix mean = e(b)
estadd matrix sd = e(p)

esttab A B C D using "${output}/tables/Table_A3b.tex", replace ///
cells(mean(fmt(2) star) sd(par) count(par("N=") fmt(0))) ///
 star(* .10 * .05 ** .01)  ///
 label nonum collabels(none) booktabs f wide mtitles("All" "Male" "Female" "\shortstack{Difference \\ p-value in par.}") ///
 refcat( any_mgr_v3  "\textbf{C. Career Outcomes (Person Level)}" , nolabel) noobs

 
 *summary stats table
eststo clear
estpost sum  `variables2'
est store A

estpost sum  `variables2' if female==0
est store B

estpost sum  `variables2' if female==1
est store C

estpost ttest `variables2', by(female) 
est store D
estadd matrix mean = e(b)
estadd matrix sd = e(p)

esttab A B C D using "${output}/tables/Table_A3c.tex", replace ///
cells(mean(fmt(2) star) sd(par) count(par("N=") fmt(0))) ///
 star(* .10 * .05 ** .01)  ///
 label nonum collabels(none) booktabs f wide mtitles("All" "Male" "Female" "\shortstack{Difference \\ p-value in par.}") ///
 refcat( any_mgr_v3  "\textbf{C. Career Outcomes (Person Level)}" , nolabel) noobs

 
}

* Table A4: Determinants of Likelihood of Holding a Senior Management Position
if `p10'==1{
	
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear

preserve
keep if year_since_grad==1
keep linkedin_id gap_total_c size_LI PL2 ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 
rename * *_y1
rename linkedin_id_y1 linkedin_id
tempfile year_1
save `year_1', replace 
restore

merge m:1 linkedin_id using `year_1'
drop _merge

eststo clear
sort linkedin_id year_since_grad


gen exp2 = exp*exp



rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

local pre_char pre_exp pre_any_mgr_v3 pre_mgr2_v3 top20 pre_PL2 
local pre_firm pre_size_LI  
local post_firm exp exp2 size_LI PL2  
local post_gap gap_total_c
local post_ind ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 
local first_job size_LI_y1 PL2_y1 ind_finance_y1 ind_consulting_y1 ind_healthcare_y1 ind_consumer_y1 ind_technology_y1


forval g=0/1{
foreach i in 5 10 15{	

*keep only one gender
preserve
keep if female == `g'

local pre_char pre_exp pre_any_mgr_v3 pre_mgr2_v3 top20 pre_PL2 
local pre_firm pre_size_LI  
local post_firm exp exp2 size_LI PL2  
local post_gap gap_total_c
local post_ind ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 
local first_job size_LI_y1 PL2_y1 ind_finance_y1 ind_consulting_y1 ind_healthcare_y1 ind_consumer_y1 ind_technology_y1




eststo K_`g'_`i':reg mgr2_v3  `pre_char' `pre_firm' `post_gap' `post_firm' `post_ind' `first_job' pre_i_* i.Class if year_since_grad==`i', robust
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
estadd local pre_firm "Yes", replace
estadd local post_firm "Yes", replace
estadd local first_job "Yes", replace
keep if e(sample)==1 // keep same sample
sum mgr2_v3 
estadd scalar r(mean), replace

restore
}
}

	 

lab var female "Female"
lab var pre_exp "Pre-MBA Experience"
lab var exp "Post-MBA Experience"
lab var exp2 "Post-MBA Experience Squared"
lab var gap_total_c "Cumulative Months of Career Break"
lab var pre_any_mgr_v3 "Pre-MBA Management Experience" 
lab var pre_mgr2_v3 "Pre-MBA Senior-Level Management Experience"
lab var pre_founder "Pre-MBA Entrepreneur"
lab var pre_i_fin "Pre-MBA Worked in Finance"
lab var pre_i_cons "Pre-MBA Worked in Consulting"
lab var pre_i_good "Pre-MBA Worked in Consumer Goods"
lab var pre_i_hlth "Pre-MBA Worked in Healthcare"
lab var pre_i_tech "Pre-MBA Worked in Tech"
lab var pre_PL "Pre-MBA P\&L Role"
lab var pre_i_oth "Pre-MBA Worked in Other Industries"
lab var pre_big "Pre-MBA Worked in Firm with 5,000+ Employees"
lab var pre_medium  "Pre-MBA Worked in Firm with 200-4,999 Employees"
lab var pre_small  "Pre-MBA Worked in Firm with Less than 200 Employees"
lab var pre_top_100_firm "Pre-MBA Worked in Top 100 MBA Firm"
lab var us_locality "U.S. Locality"
lab var top20 "Top-20 Undergrad"
lab var ivy "Ivy League Undergrad"
lab var small "Working in Firm with Less than 200 Employees"
lab var medium "Working in Firm with 200-4,999 Employees"
lab var big "Working in Firm with 5,000+ Employees"
lab var PL "P\&L Role"
lab var pre_PL2 "Pre-MBA P\&L Role"
lab var pre_size_LI "Pre-MBA Firm Size"
lab var size_LI_y1 "Firm Size in in Year 1"
lab var PL2_y1 "P\&L Role in Year 1"
lab var ind_finance_y1 "Worked in Finance in Year 1"
lab var ind_consulting_y1 "Worked in Consulting in Year 1"
lab var ind_healthcare_y1 "Worked in Healthcare in Year 1"
lab var ind_consumer_y1 "Worked in Consumer Goods in Year 1"
lab var ind_technology_y1 "Worked in Tech in Year 1"
	 
esttab K_0_5 K_0_10 K_0_15 K_1_5 K_1_10 K_1_15 using "${output}/tables/Table_A4.tex", replace ///
	 keep( `pre_char' `pre_firm' `first_job' pre_i_*) ///
	 b(3) se star(* .10 ** .05 *** .01) r2 ///
	 s(classfe mean r2 N  , ///
	 label("Class FE" ///
	 "Mean" "\(R^2\)" "N" ) ///
	 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("\shortstack{5 Years \\ Post-MBA}" ///
	 "\shortstack{10 Years \\ Post-MBA}" ///
	 "\shortstack{15 Years \\ Post-MBA}" ///
	 "\shortstack{5 Years \\ Post-MBA}" ///
	 "\shortstack{10 Years \\ Post-MBA}" ///
	 "\shortstack{15 Years \\ Post-MBA}")  ///
	 mgroups("Male"  "Female", pattern(1 0 0 1 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) ///
		span erepeat(\cmidrule(lr){@span})) booktabs f noomitted nobaselevel
	 


}

* Table A5: Gender Gap in Senior Management: Pooled Sample (Detailed Controls)
if `p11'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear


eststo clear
keep if year_since_grad>=1 & year_since_grad<=15
sort linkedin_id year_since_grad


gen exp2 = exp*exp



rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

local pre_char pre_exp pre_any_mgr_v3 pre_mgr2_v3 top20 pre_PL2 
local pre_firm pre_size_LI  
local post_firm exp exp2 size_LI PL2  
local post_gap gap_total_c
local post_ind ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 




eststo H:reg mgr2_v3 female  `pre_char' `pre_firm' `post_gap' `post_firm' `post_ind' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
estadd local pre_firm "Yes", replace
estadd local post_firm "Yes", replace
keep if e(sample)==1 // keep same sample
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace



eststo A:reg mgr2_v3 female i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace

eststo C:reg mgr2_v3 female `pre_char' `pre_firm' i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace

eststo D:reg mgr2_v3 female `pre_char' `pre_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


eststo E:reg mgr2_v3 female `pre_char' `pre_firm' `post_gap' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


eststo F:reg mgr2_v3 female `pre_char' `pre_firm' `post_gap' `post_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
estadd local pre_firm "Yes", replace
estadd local post_firm "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


lab var female "Female"
lab var pre_exp "Pre-MBA Experience"
lab var exp "Post-MBA Experience"
lab var exp2 "Post-MBA Experience Squared"
lab var gap_total_c "Cumulative Months of Career Break"
lab var pre_any_mgr_v3 "Pre-MBA Management Experience" 
lab var pre_mgr2_v3 "Pre-MBA Senior-Level Management Experience"
lab var pre_founder "Pre-MBA Entrepreneur"
lab var pre_i_fin "Pre-MBA Worked in Finance"
lab var pre_i_cons "Pre-MBA Worked in Consulting"
lab var pre_i_good "Pre-MBA Worked in Consumer Goods"
lab var pre_i_hlth "Pre-MBA Worked in Healthcare"
lab var pre_i_tech "Pre-MBA Worked in Tech"
lab var pre_PL "Pre-MBA P\&L Role"
lab var pre_i_oth "Pre-MBA Worked in Other Industries"
lab var pre_big "Pre-MBA Worked in Firm with 5,000+ Employees"
lab var pre_medium  "Pre-MBA Worked in Firm with 200-4,999 Employees"
lab var pre_small  "Pre-MBA Worked in Firm with Less than 200 Employees"
lab var pre_top_100_firm "Pre-MBA Worked in Top 100 MBA Firm"
lab var us_locality "U.S. Locality"
lab var top20 "Top-20 Undergrad"
lab var ivy "Ivy League Undergrad"
lab var small "Working in Firm with Less than 200 Employees"
lab var medium "Working in Firm with 200-4,999 Employees"
lab var big "Working in Firm with 5,000+ Employees"
lab var PL "P\&L Role"
lab var pre_PL2 "Pre-MBA P\&L Role"
lab var pre_size_LI "Pre-MBA Firm Size"

	 
	 
esttab A C D using "${output}/tables/Table_A5.tex", replace ///
	 keep(female `pre_char' `pre_firm' pre_i_*) b(3) se star(* .10 ** .05 *** .01) r2 ///
	 s(classfe mean male_mean r2 N  , ///
	 label("Class x Year FE" ///
	 "Mean" "Mean (Male)" "\(R^2\)" "N" ) ///
	 fmt(%9.3f %9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") nomtitles booktabs f noomitted nobaselevel
	 
	
}

* Table A6: Section-Level Characteristics Correlated with Higher Proportion of Female Peers
if `p12'==1{
use "${data}/raw/LI_workhistory_yearly_educ_gender_fake.dta",clear
keep if Class>=2000 & Class<=2018
keep if year_since_grad >=1 & year_since_grad <=15
bys linkedin_id:keep if _n==1
drop femaleshare_section
gen femaleshare_sectiont = femaleshare if female==0
bys section_id: egen femaleshare_section = max(femaleshare_sectiont)

*collapse into a group level dataset 
collapse (mean) pre_* us_locality top20 ivy female  (first) m_white m_foreign,by(femaleshare_section section_id Class)

*identify below and above median femaleshare sections
bys Class: egen femaleshare_med = median(femaleshare_section)
bys Class: egen femaleshare_p25 = pctile(femaleshare_section), p(25)
bys Class: egen femaleshare_p75 = pctile(femaleshare_section), p(75)

gen above_med = femaleshare_section>=femaleshare_med

 
local variables pre_exp pre_any_mgr_v3 pre_mgr2_v3 pre_founder pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth pre_small pre_medium pre_big pre_ihs_stars_med pre_PL2 us_locality top20 m_white m_foreign 

lab var pre_exp "Pre-MBA Years of Experience"
lab var pre_any_mgr_v3 "Any Management Experience" 
lab var pre_mgr2_v3 "Any Senior-Level Management Experience"
lab var pre_founder "Entrepreneur"
lab var pre_i_fin "Finance"
lab var pre_i_cons "Consulting"
lab var pre_i_good "Consumer Goods"
lab var pre_i_hlth "Healthcare"
lab var pre_i_tech "Tech"
lab var pre_i_oth "Other Industries"
lab var pre_big "5,000+ Employees"
lab var pre_medium  "200-4,999 Employees"
lab var pre_small  "Less than 200 Employees"
lab var pre_top_100_firm "Worked in Top-100 MBA Firm"
lab var pre_ihs_stars_med "Worked in Female-Friendly Firm"
lab var pre_PL2 "Worked in a P\&L Role"
lab var us_locality "U.S. Locality"
lab var top20 "Top-20 Undergrad"
lab var ivy "Ivy League Undergrad"
lab var m_white "White"
lab var m_foreign "Foreign"

cap file close myfile
file open myfile using "${output}/tables/Table_A6.tex", write replace
file write myfile "\begin{tabular}{lccccc}" _n ///
	"\toprule" _n ///
	" & (1) & (2) & (3) & (4) & (5) \\" _n ///
	"Section Characteristics & Full Sample & \shortstack{Mean for \\ Above-Median \\ Female Share \\ Sections} & \shortstack{Mean for \\ Below-Median \\ Female Share  \\Sections} & Coefficient & \(p\)-value \\" _n ///
	"\midrule" _n /// 
	"\textit{Share of Section with ...} & & & & & \\" _n

foreach x of local variables{
	local varlabel : variable label `x'
	sum `x'
	scalar mean_all = r(mean)
	local mean_all: di %9.3f scalar(mean_all)
	sum `x' if above_med==1
	scalar mean1 = r(mean)
	local mean1: di %9.3f scalar(mean1)
	sum `x' if above_med==0
	scalar mean2 = r(mean)
	local mean2: di %9.3f scalar(mean2)
	reg femaleshare_section `x' i.Class,robust
	scalar beta = _b[`x']
	local beta: di %9.3f scalar(beta)
	local t = _b[`x']/_se[`x']
	scalar p =2*ttail(e(df_r),abs(`t'))
	local p: di %9.3f scalar(p)
	
	local star = ""
	if `p'<=0.1 & `p'>.05{
		local star = "\sym{*}" 
	}
	else if `p'<=0.05 & `p'>.01{
		local star = "\sym{**}"
	}
	if `p'<=0.01{
		local star = "\sym{***}"
	}
	
	file write myfile "\quad `varlabel' & `mean_all' & `mean1' & `mean2' & `beta' & `p'`star' \\" _n
}
count 
local n = `r(N)'
count if above_med==1
local n1 = `r(N)'
count if above_med==0
local n2 = `r(N)'
file write myfile "\midrule" _n
file write myfile "Observations & `n' & `n1' & `n2' & `n' & `n' \\" _n
file write myfile "\bottomrule" _n "\end{tabular}" 
file close myfile
}

* Table A7: Randomization Test - Female Pre-MBA Characteristics (Caeyers and Fafchamps, 2024)
if `p13'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
keep if year_since_grad>=1 & year_since_grad<=15

bys linkedin_id: keep if _n==1

bys Class: gen n_class = _N
bys section_id: gen n_section = _N

keep Class SectionGroupNumber n_class n_section

bys Class SectionGroupNumber: keep if _n==1

gen L_k = n_class
gen K_k = n_section
egen M = total(K_k)


*Proposition 2 equation 5 
gen plim = - (L_k -1)*(K_k-1)/((L_k-K_k)*L_k + (K_k-1))
gen s2_zk = ((K_k - 1) + (L_k - K_k)*L_k)/(L_k*(L_k-1)*(K_k-1))
gen s2_zt = K_k/M*s2_zk 
egen s2_z = total(s2_zt)

gen rhot = K_k/M*(s2_zk/s2_z)*plim
egen rho = total(rhot)

keep if _n==1
levelsof rho , local(rho)


use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
keep if year_since_grad>=1 & year_since_grad<=15
keep if female==1
gen rho = `rho'

bys linkedin_id: egen top20_new = max(top20)
replace top20_new=. if top20_new==99

bys linkedin_id: egen ivy_new = max(ivy)
replace ivy_new=. if ivy_new==99


bys linkedin_id: keep if _n==1

replace pre_mgr2_v3=. if pre_mgr2_v3==99
replace pre_i_fin=. if pre_i_fin==99
replace pre_exp=. if pre_exp==99
replace pre_any_mgr_v3=. if pre_any_mgr_v3==99
replace pre_founder=. if pre_founder==99
replace pre_i_cons=. if pre_i_cons==99
replace pre_i_good=. if pre_i_good==99
replace pre_i_hlth=. if pre_i_hlth==99
replace pre_i_tech=. if pre_i_tech==99
replace pre_i_oth=. if pre_i_oth==99
replace pre_big=. if pre_big==99
replace pre_medium=. if pre_medium==99
replace pre_small=. if pre_small==99
replace pre_top_100_firm =. if pre_top_100_firm==99
replace pre_ihs_stars_med=. if pre_ihs_stars_med==99
replace pre_PL2=. if pre_PL2==99
replace us_locality=. if us_locality==99
replace m_white=. if m_white==99
replace m_foreign=. if m_foreign==99

gen female_top20_tilde = top20_new - rho*femaleshare // Top-20 Undergrad
gen female_ivy_tilde = ivy_new - rho*femaleshare // Ivy League Undergrad

gen female_pre_exp_tilde = pre_exp - rho*femaleshare // Pre-MBA Years of Experience
gen female_pre_mgr2_v3_tilde = pre_mgr2_v3 - rho*femaleshare // Any Senior-Level Management Experience
gen female_pre_any_mgr_v3_tilde = pre_any_mgr_v3 - rho*femaleshare // Any Management Experience

gen female_pre_i_fin_tilde = pre_i_fin - rho*femaleshare // Finance
gen female_pre_founder_tilde = pre_founder - rho*femaleshare // Entrepreneur
gen female_pre_i_cons_tilde = pre_i_cons - rho*femaleshare // Consulting
gen female_pre_i_good_tilde = pre_i_good - rho*femaleshare // Consumer Goods
gen female_pre_i_hlth_tilde = pre_i_hlth - rho*femaleshare // Healthcare
gen female_pre_i_tech_tilde = pre_i_tech - rho*femaleshare // Technology
gen female_pre_i_oth_tilde = pre_i_oth - rho*femaleshare // Other Industries

gen female_pre_big_tilde = pre_big - rho*femaleshare // 5,000+ Employees
gen female_pre_medium_tilde = pre_medium - rho*femaleshare // 200-4,999 Employees
gen female_pre_small_tilde = pre_small - rho*femaleshare // Less than 200 Employees

gen female_pre_100_firm_t = pre_top_100_firm - rho*femaleshare // Worked in Top-100 MBA Firm
gen female_pre_ihs_stars_t = pre_ihs_stars_med - rho*femaleshare // Worked in Female-Friendly Firm
gen female_pre_PL2_tilde = pre_PL2 - rho*femaleshare // Worked in a P\&L Role

gen female_us_locality_tilde = us_locality - rho*femaleshare // U.S. Locality
gen female_m_white_tilde = m_white - rho*femaleshare // White
gen female_m_foreign_tilde = m_foreign - rho*femaleshare // Foreign



lab var female_top20_tilde "Top-20 Undergrad"
lab var female_ivy_tilde "Ivy Undergrad"
lab var female_pre_exp_tilde "Pre-MBA Years of Experience"
lab var female_pre_mgr2_v3_tilde "Pre-MBA Senior Manager"
lab var female_pre_any_mgr_v3_tilde "Pre-MBA Manager"
lab var female_pre_i_fin_tilde "Pre-MBA Finance"
lab var female_pre_i_cons_tilde "Pre-MBA Consulting"
lab var female_pre_i_good_tilde "Pre-MBA Consumer Goods"
lab var female_pre_i_hlth_tilde "Pre-MBA Healthcare"
lab var female_pre_i_tech_tilde "Pre-MBA Tech"
lab var female_pre_i_oth_tilde "Pre-MBA Other Industries"
lab var female_pre_big_tilde "Pre-MBA Firm Size: 5,000+ Employees"
lab var female_pre_medium_tilde "Pre-MBA Firm Size: 200-4,999 Employees"
lab var female_pre_small_tilde "Pre-MBA Firm Size: Less than 200 Employees"


foreach var in female_top20_tilde female_ivy_tilde  ///
		female_pre_exp_tilde female_pre_mgr2_v3_tilde female_pre_any_mgr_v3_tilde ///
		female_pre_i_fin_tilde female_pre_i_cons_tilde female_pre_i_good_tilde female_pre_i_hlth_tilde female_pre_i_tech_tilde female_pre_i_oth_tilde ///
		female_pre_big_tilde female_pre_medium_tilde female_pre_small_tilde ///
		female_pre_100_firm_t female_pre_ihs_stars_t female_pre_PL2_tilde ///
		female_us_locality_tilde female_m_white_tilde female_m_foreign_tilde { /// 
	
	eststo `var': reg `var' femaleshare i.Class, cluster(Class)
	estadd local classfe "Yes" , replace

}




local lab: variable label female_top20_tilde
esttab  female_top20_tilde ///
	using  "${output}/tables/Table_A7.tex", replace ///
	se label coeflabel(femaleshare "`lab'") eqlabels(none) wide keep(femaleshare )  ///
	mtitles("Female Share") collabel("\(\beta\)" "SE") noomitted star(* .10 ** .05 *** .01) nogaps ///
	booktabs f noobs noconstant cells("b( fmt(3) star) se(par fmt(3))")

foreach x in  female_ivy_tilde  /// 
		female_pre_exp_tilde female_pre_mgr2_v3_tilde female_pre_any_mgr_v3_tilde ///
		female_pre_i_fin_tilde female_pre_i_cons_tilde female_pre_i_good_tilde female_pre_i_hlth_tilde female_pre_i_tech_tilde ///
		female_pre_i_oth_tilde female_pre_big_tilde female_pre_medium_tilde female_pre_small_tilde {  
	local lab: variable label `x'
	esttab  `x' ///
	using  "${output}/tables/Table_A7.tex", append ///
	se label coeflabel(femaleshare "`lab'") eqlabels(none) wide keep(femaleshare )  ///
	nomtitles collabel(none) noomitted nogaps cells("b( fmt(3) star) se(par fmt(3))")   ///
	booktabs f noobs plain	noconstant star(* .10 ** .05 *** .01)
}

 
 ******** GMAT
use "${data}/raw/analysis_sections_fake.dta", clear

keep if gender==1
bys MasterPersonID: keep if _n==1


gen rho = `rho'


 gen gmat_tilde = GMAT - rho*female_share // Top-20 Undergrad

 foreach var in gmat_tilde { 
	eststo `var': reg `var' female_share i.Class, cluster(Class)
	estadd local classfe "Yes" , replace

}
lab var gmat_tilde "GMAT"




foreach x in  gmat_tilde{  
	local lab: variable label `x'
	esttab  `x' ///
	using  "${output}/tables/Table_A7.tex", append ///
	se label coeflabel(female_share "`lab'") eqlabels(none) wide keep(female_share )  ///
	nomtitles collabel(none) noomitted nogaps cells("b( fmt(3) star) se(par fmt(3))")   ///
	booktabs f noobs plain	noconstant star(* .10 ** .05 *** .01)
}

	
}

* Table A8: Effect of Female Peers on Management Seniority Level, Employment, and Entrepreneurship
if `p14'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay
gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

gen log_gd_i_totalpay = ln(gd_i_totalpay+1)
gen log_gd_i_bonuspay = ln(gd_i_bonuspay+1)
gen log_gd_i_basepay = ln(gd_i_basepay+1)

replace gd_i_basepay = gd_i_basepay/1000
replace gd_i_bonuspay = gd_i_bonuspay/1000
replace gd_i_totalpay = gd_i_totalpay/1000

preserve
collapse femaleshare_ind = female , by(i_categorical)
keep i_categorical femaleshare_ind
tempfile femaleshare_ind
save `femaleshare_ind', replace
restore

merge m:1 i_categorical using `femaleshare_ind'
drop _merge

*POOLED REGRESSIONS
foreach x in any_mgr_v3 vp_dir_v3 svp_v3 csuite_v3 employed gap_total_c founder ///
			{
			
		
		eststo `x': reg `x' femaleshare_male ///
		femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace

	
	
		if "`x'"=="paid_weeks" ///
			| "`var'"=="firm_flexible" | "`x'" == "fam_friendly_index2" ///
			| "`x'" == "board_women_pct" | "`x'" == "fam_friendly_index2_m_r" {
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female, cluster(section_id)
		 
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "gd_i_basepay" | "`x'" == "gd_i_basepay_imp" ///
			| "`x'" == "gd_i_totalpay" | "`x'" == "gd_i_totalpay_imp" ///
			| "`x'" == "gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_totalpay" | "`x'" == "log_gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_basepay" {
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean) 
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace

		eststo `x'_i_sm: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			  c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.mgr_cat_broad##i.female [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i_sm, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			estadd local mgr_cat_fe "Yes" , replace
		}
		
		
		if "`x'" == "gd_fem_pct_d_basepay" | "`x'" == "gd_sr_mgr_fem_pct_d_base" ///
			| "`x'" == "gd_fem_share_emp" | "`x'" == "gd_fem_share_sr_mgr" ///
			| "`x'" == "gd_basepay" | "`x'" == "gd_basepaysenior_manager" ///
			| "`x'" == "gd_totalpay" | "`x'" == "gd_totalpaysenior_manager" ///
			| "`x'" == "gd_fem_pct_totpay" | "`x'" == "gd_sr_mgr_fem_pct_totpay"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "ihs_stars" | "`x'" == "ihs_stars_m_r" | "`x'" == "ihs_stars_m_r_mgr" | "`x'" == "n_ihs_stars_m_r_mgr" ///
			| "`x'" == "ihs_stars_l" | "`x'" == "ihs_stars_u" ///
			| "`x'" == "ihs_stars_q1" | "`x'" == "ihs_stars_q2" | "`x'" == "ihs_stars_q3" | "`x'" == "ihs_stars_q4" ///
			| "`x'" == "ihs_stars_med" | "`x'" == "ihs_stars_med_mgr" | "`x'" == "ihs_stars_no_med_mgr" ///
			| "`x'" == "ihs_stars_q1_mgr" | "`x'" == "ihs_stars_q2_mgr" ///
			| "`x'" == "ihs_stars_q3_mgr" | "`x'" == "ihs_stars_q4_mgr" ///
			| "`x'" == "ihs_stars_q1_male_mgr2_v3" | "`x'" == "ihs_stars_q2_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_male_mgr2_v3" | "`x'" == "ihs_stars_q4_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q1_fem_mgr2_v3" | "`x'" == "ihs_stars_q2_fem_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_fem_mgr2_v3" | "`x'" == "ihs_stars_q4_fem_mgr2_v3" ///
			| "`x'" == "ihs_remote" | "`x'" == "ihs_employer" | "`x'" == "ihs_genderequal" ///
			| "`x'" == "ihs_familysupport" | "`x'" == "ihs_femaleleader" | "`x'" == "ihs_flexible" ///
			| "`x'" == "ihs_learning" | "`x'" == "ihs_mgmtopp" | "`x'" == "ihs_ML" | "`x'" == "ihs_paidtimeoff" ///
			| "`x'" == "ihs_salarysatisfy" | "`x'" == "ihs_belonging" | "`x'" == "ihs_social" ///
			| "`x'" == "ihs_sponsorship" | "`x'" == "ihs_diversity" | "`x'" == "ihs_people" ///
			| "`x'" == "ihs_wellness" | "`x'" == "ihs_dads_have_pl" | "`x'" == "ihs_received" ///
			| "`x'" == "ihs_growth" | "`x'" == "ihs_support" | "`x'" == "ihs_agree" ///
			| "`x'" == "ihs_opportunities_med" | "`x'" == "ihs_flexibility_med" | "`x'" == "ihs_enrichment_med" ///
			| "`x'" == "ihs_compensation_med" | "`x'" == "ihs_family_med" | "`x'" == "ihs_culture_med"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=ihs_ratings_count], cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		

		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=ihs_ratings_count], cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="fgb_rating"{
				eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=fgb_reviews], cluster(section_id)
			
			sum `x' [aweight=fgb_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=fgb_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=fgb_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="size_LI" | "`x'"=="small" | "`x'"=="medium" | ///
			"`x'"=="big" | "`x'"=="top_100_firm" {
			
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
		
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female, cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}

}

	 

	 
esttab  vp_dir_v3 svp_v3 csuite_v3 employed gap_total_c any_mgr_v3 founder using "${output}/tables/Table_A8.tex", replace ///
	 keep(femaleshare_male femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(p_value mean_f mean_m r2 N classfe, ///
	 label("\(p\)-value Male vs. Female" "Female Mean" "Male Mean" "\(R^2\)" "N" ///
	 "Class x Year x Female FE") ///
	 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles( "\shortstack{Director \\ and VP}" ///
	 "SVP" "C-Suite" "Employed" "\shortstack{Cumulative \\ Months \\ In \\ Nonemployment}" "\shortstack{Any-Level \\ Manager}" "\shortstack{Entrepreneurship}") booktabs f noomitted nobaselevel	
}

* Table A9: Effect of Female Peers on Dynamics in Senior Management Positions
if `p15'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge

*create number of positions
sort linkedin_id year_since_grad ,stable
gen new_position =  (job_id!=job_id[_n-1])
gen new_position_mgr =  (new_position==1 & mgr2_v3==1)
replace new_position_mgr=. if new_position==. | mgr2_v3==.
bys linkedin_id: egen tot_position_mgr = total(new_position_mgr)
bys linkedin_id: egen tot_position = total(new_position)


*create frst time manager
bys linkedin_id: gen n_position_mgr = sum(new_position_mgr)
gen year_first_position_mgr_t = year_since_grad if n_position_mgr==1 & new_position_mgr==1
bys linkedin_id: egen year_first_position_mgr = max(year_first_position_mgr_t)

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)


*POOLED REGRESSIONS
foreach x in mgr2_v3_tot_years year_first_position_mgr tot_position_mgr  external_mgr internal_mgr ///
			{
		preserve
		
		if inlist("`x'","external_mgr","internal_mgr")!=1{
			bys linkedin_id: keep if _n==1
		}
		
		eststo `x': reg `x' femaleshare_male ///
		femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace

	
	
		if "`x'"=="paid_weeks" ///
			| "`var'"=="firm_flexible" | "`x'" == "fam_friendly_index2" ///
			| "`x'" == "board_women_pct" | "`x'" == "fam_friendly_index2_m_r" {
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female, cluster(section_id)
		 
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "gd_i_basepay" | "`x'" == "gd_i_basepay_imp" ///
			| "`x'" == "gd_i_totalpay" | "`x'" == "gd_i_totalpay_imp" ///
			| "`x'" == "gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_totalpay" | "`x'" == "log_gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_basepay" {
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean) 
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace

		eststo `x'_i_sm: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			  c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.mgr_cat_broad##i.female [aweight=gd_i_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i_sm, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			estadd local mgr_cat_fe "Yes" , replace
		}
		
		
		if "`x'" == "gd_fem_pct_d_basepay" | "`x'" == "gd_sr_mgr_fem_pct_d_base" ///
			| "`x'" == "gd_fem_share_emp" | "`x'" == "gd_fem_share_sr_mgr" ///
			| "`x'" == "gd_basepay" | "`x'" == "gd_basepaysenior_manager" ///
			| "`x'" == "gd_totalpay" | "`x'" == "gd_totalpaysenior_manager" ///
			| "`x'" == "gd_fem_pct_totpay" | "`x'" == "gd_sr_mgr_fem_pct_totpay"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_reviews], cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "ihs_stars" | "`x'" == "ihs_stars_m_r" | "`x'" == "ihs_stars_m_r_mgr" | "`x'" == "n_ihs_stars_m_r_mgr" ///
			| "`x'" == "ihs_stars_l" | "`x'" == "ihs_stars_u" ///
			| "`x'" == "ihs_stars_q1" | "`x'" == "ihs_stars_q2" | "`x'" == "ihs_stars_q3" | "`x'" == "ihs_stars_q4" ///
			| "`x'" == "ihs_stars_med" | "`x'" == "ihs_stars_med_mgr" | "`x'" == "ihs_stars_no_med_mgr" ///
			| "`x'" == "ihs_stars_q1_mgr" | "`x'" == "ihs_stars_q2_mgr" ///
			| "`x'" == "ihs_stars_q3_mgr" | "`x'" == "ihs_stars_q4_mgr" ///
			| "`x'" == "ihs_stars_q1_male_mgr2_v3" | "`x'" == "ihs_stars_q2_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_male_mgr2_v3" | "`x'" == "ihs_stars_q4_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q1_fem_mgr2_v3" | "`x'" == "ihs_stars_q2_fem_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_fem_mgr2_v3" | "`x'" == "ihs_stars_q4_fem_mgr2_v3" ///
			| "`x'" == "ihs_remote" | "`x'" == "ihs_employer" | "`x'" == "ihs_genderequal" ///
			| "`x'" == "ihs_familysupport" | "`x'" == "ihs_femaleleader" | "`x'" == "ihs_flexible" ///
			| "`x'" == "ihs_learning" | "`x'" == "ihs_mgmtopp" | "`x'" == "ihs_ML" | "`x'" == "ihs_paidtimeoff" ///
			| "`x'" == "ihs_salarysatisfy" | "`x'" == "ihs_belonging" | "`x'" == "ihs_social" ///
			| "`x'" == "ihs_sponsorship" | "`x'" == "ihs_diversity" | "`x'" == "ihs_people" ///
			| "`x'" == "ihs_wellness" | "`x'" == "ihs_dads_have_pl" | "`x'" == "ihs_received" ///
			| "`x'" == "ihs_growth" | "`x'" == "ihs_support" | "`x'" == "ihs_agree" ///
			| "`x'" == "ihs_opportunities_med" | "`x'" == "ihs_flexibility_med" | "`x'" == "ihs_enrichment_med" ///
			| "`x'" == "ihs_compensation_med" | "`x'" == "ihs_family_med" | "`x'" == "ihs_culture_med"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=ihs_ratings_count], cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		

		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=ihs_ratings_count], cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="fgb_rating"{
				eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=fgb_reviews], cluster(section_id)
			
			sum `x' [aweight=fgb_reviews] if female==1, d
			local mean_f = r(mean)
			sum `x' [aweight=fgb_reviews] if female==0, d
			local mean_m = r(mean)
			
			sum `x' [aweight=fgb_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="size_LI" | "`x'"=="small" | "`x'"=="medium" | ///
			"`x'"=="big" | "`x'"=="top_100_firm" {
			
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
		
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female, cluster(section_id)
			
			sum `x' if female==1, d
			local mean_f = r(mean)
			sum `x' if female==0, d
			local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		restore
}

esttab mgr2_v3_tot_years year_first_position_mgr tot_position_mgr  external_mgr internal_mgr using "${output}/tables/Table_A9.tex", replace ///
	 keep(femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(mean_f mean_m r2 N classfe, ///
	 label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
	 "Class x Year x Female FE") ///
	 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("\shortstack{Total Number \\ of Years as \\ Senior Manager \\ Positions}" 	"\shortstack{Years to First \\ Senior Manager \\ Position}" ///
	 "\shortstack{Total Positions as \\ Senior Manager}" "\shortstack{External \\ Promotion}" ///
	 "\shortstack{Internal \\ Promotion}" ) mgroups("" "Senior Manager", pattern(0 0 0 1 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) ///
		span erepeat(\cmidrule(lr){@span})) booktabs f noomitted nobaselevel	
}

* Table A10: Gender Differences in Total Compensation (Imputed)
if `p16'==1{
* VERSION WTIHOUT ADDITIONAL FIRM DATA OTHER THAN LINKEDIN's
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
//keep if Class <=2015


eststo clear
keep if year_since_grad>=1 & year_since_grad<=15
sort linkedin_id year_since_grad


gen exp2 = exp*exp



rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

local pre_char pre_exp pre_any_mgr_v3 pre_mgr2_v3 top20 pre_PL2 //pre_gd_i_totalpay
local pre_firm pre_size_LI  //pre_gd_totalpay pre_gd_fem_pct_d_totalpay pre_ihs_stars
local post_firm exp exp2 size_LI PL2  //gd_basepay gd_basepaysenior_manager gd_totalpay gd_totalpaysenior_manager gd_fem_pct_totpay gd_sr_mgr_fem_pct_totpay  ihs_stars
local post_gap gap_total_c
local post_ind ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 
local post_mgr mgr_cat_broad

gen log_gd_i_totalpay = ln(gd_i_totalpay+1)

foreach y in  log_gd_i_totalpay  {
	*replace `y' = `y'/1000


	eststo H:reg log_gd_i_totalpay female  `pre_char' `pre_firm' `post_gap' `post_firm' `post_ind' `post_mgr' pre_i_* i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local preindustryfe "Yes" , replace
	estadd local postindustryfe "Yes" , replace
	estadd local post_mgr "Yes" , replace
	estadd local postgap "Yes" , replace
	estadd local pre_char "Yes", replace
	estadd local pre_firm "Yes", replace
	estadd local post_firm "Yes", replace
	keep if e(sample)==1 // keep same sample
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace



	eststo A:reg log_gd_i_totalpay female i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace

	eststo C:reg log_gd_i_totalpay female `pre_char' `pre_firm' i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local pre_char "Yes", replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace


	eststo D:reg log_gd_i_totalpay female `pre_char' `pre_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local preindustryfe "Yes" , replace
	estadd local pre_char "Yes", replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace

	eststo E:reg log_gd_i_totalpay female `pre_char' `pre_firm' `post_gap' pre_i_* i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local preindustryfe "Yes" , replace
	estadd local postgap "Yes" , replace
	estadd local pre_char "Yes", replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace

	eststo F:reg log_gd_i_totalpay female `pre_char' `pre_firm' `post_gap' `post_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local preindustryfe "Yes" , replace
	estadd local postgap "Yes" , replace
	estadd local pre_char "Yes", replace
	estadd local pre_firm "Yes", replace
	estadd local post_firm "Yes", replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace

	eststo G:reg log_gd_i_totalpay female `pre_char' `pre_firm' `post_gap' `post_firm' `post_ind' pre_i_* i.Class##i.year, cluster(linkedin_id)
	estadd local classfe "Yes" , replace
	estadd local preindustryfe "Yes" , replace
	estadd local postindustryfe "Yes" , replace
	estadd local postgap "Yes" , replace
	estadd local pre_char "Yes", replace
	estadd local pre_firm "Yes", replace
	estadd local post_firm "Yes", replace
	sum `y' 
	estadd scalar r(mean), replace
	sum `y' if female==0
	scalar male_mean = r(mean)
	estadd scalar male_mean, replace

	lab var female "Female"
	lab var pre_exp "Pre-MBA Experience"
	lab var exp "Post-MBA Experience"
	lab var exp2 "Post-MBA Experience Squared"
	lab var gap_total_c "Cumulative Months of Career Break"
	lab var pre_any_mgr_v3 "Pre-MBA Management Experience" 
	lab var pre_gd_i_totalpay "Pre-MBA Senior-Level Management Experience"
	lab var pre_founder "Pre-MBA Entrepreneur"
	lab var pre_i_fin "Worked in Finance"
	lab var pre_i_cons "Worked in Consulting"
	lab var pre_i_good "Worked in Consumer Goods"
	lab var pre_i_hlth "Worked in Healthcare"
	lab var pre_i_tech "Worked in Tech"
	lab var pre_PL "Pre-MBA P\&L Role"
	lab var pre_i_oth "Worked in Other Industries"
	lab var pre_big "Worked in Firm with 5,000+ Employees"
	lab var pre_medium  "Worked in Firm with 200-4,999 Employees"
	lab var pre_small  "Worked in Firm with Less than 200 Employees"
	lab var pre_top_100_firm "Worked in Top 100 MBA Firm"
	lab var us_locality "U.S. Locality"
	lab var top20 "Top-20 Undergrad"
	lab var ivy "Ivy League Undergrad"
	lab var small "Working in Firm with Less than 200 Employees"
	lab var medium "Working in Firm with 200-4,999 Employees"
	lab var big "Working in Firm with 5,000+ Employees"
	lab var PL "P\&L Role"

	esttab A C D E F G H using "${output}/tables/Table_A10.tex", replace ///
		 keep(female ) se star(* .10 ** .05 *** .01) r2 ///
		 s(classfe pre_char preindustryfe postgap post_firm postindustryfe post_mgr  mean male_mean r2 N  , ///
		 label("Class x Year FE" "Pre-MBA Characteristics"  ///
		 "Pre-MBA Industry FE" "Cummulative Months of Career Break" "Post-MBA Characteristics" "Post-MBA Industry FE" "Current Broad Managerial Category"  ///
		 "Mean" "Mean (Male)" "\(R^2\)" "N" )) ///
		 label interaction(" $\times$ ") nomtitles booktabs f noomitted nobaselevel
	 
}
}

* Table A11: Effect of Female Peers on Senior Management Controlling for Firm Size and Firm Average Compensation
if `p17'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15

sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'


*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay


bys linkedin_id: gen years_count = _N

foreach x in mgr2_v3 {
		
		eststo `x'_main: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum `x' if female==1, d
        local mean_f = r(mean)
        sum `x' if female==0, d
        local mean_m = r(mean)
			
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_main, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		preserve
		replace mgr2_v3=0 if employed_filled==0
		eststo `x'_filled: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum `x' if female==1, d
        local mean_f = r(mean)
        sum `x' if female==0, d
        local mean_m = r(mean)
			
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_filled, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		restore
		
		eststo mgr2_v3_nof: reg mgr2_v3_nof femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum `x' if female==1, d
        local mean_f = r(mean)
        sum `x' if female==0, d
        local mean_m = r(mean)
			
		sum mgr2_v3_nof, d
		local mean = r(mean)
		local sd = r(sd)
		eststo mgr2_v3_nof, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		eststo `x'_b: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if Class>=2000 & Class<=2008 & years_count==15, cluster(section_id)
		 
		sum `x' if Class>=2000 & Class<=2008 & years_count==15 & female==1, d
        local mean_f = r(mean)
        sum `x' if Class>=2000 & Class<=2008 & years_count==15 & female==0, d
        local mean_m = r(mean)
			
		sum `x' if Class>=2000 & Class<=2008 & years_count==15, d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_b, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		eststo `x'_ihs: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if ihs_stars!=. , cluster(section_id)
		 
		sum `x' if ihs_stars!=. & female==1, d
        local mean_f = r(mean)
        sum `x' if ihs_stars!=. & female==0, d
        local mean_m = r(mean)
			
		sum `x' if ihs_stars!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_ihs, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		eststo `x'_male: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if i_male!=. , cluster(section_id)
		 
		sum `x' if i_male!=. & female==1, d
        local mean_f = r(mean)
        sum `x' if i_male!=. & female==0, d
        local mean_m = r(mean)
			
		sum `x' if i_male!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_male, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		eststo `x'_cluster: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(Class)
		 
		sum `x' if female==1, d
        local mean_f = r(mean)
        sum `x' if female==0, d
        local mean_m = r(mean)
			
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_cluster, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		preserve
		bys section_id: keep if _n==1
		sum femaleshare_section, d
		local p1 = `r(p1)'
		local p99 = `r(p99)'
		restore
		eststo `x'_outliers: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if femaleshare>=`p1' & femaleshare<=`p99', cluster(Class)
		 
		sum `x' if femaleshare>=`p1' & femaleshare<=`p99' & female==1, d
        local mean_f = r(mean)
        sum `x' if femaleshare>=`p1' & femaleshare<=`p99' & female==0, d
        local mean_m = r(mean)
			
		sum `x' if femaleshare>=`p1' & femaleshare<=`p99', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_outliers, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		
		eststo `x'_controls: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 c.size_LI##i.female ///
			 c.gd_totalpay##i.female ///
			 i.PL##i.female ///
		, cluster(Class)
		 
		sum `x' if female==1, d
        local mean_f = r(mean)
        sum `x' if female==0, d
        local mean_m = r(mean)
			
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_controls, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace


		eststo `x'_indfe: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			i.i_categorical, cluster(section_id)
		 
		sum `x' if i_categorical!=. & female==1, d
        local mean_f = r(mean)
        sum `x' if i_categorical!=. & female==0, d
        local mean_m = r(mean)
			
		sum `x' if i_categorical!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_indfe, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		
		eststo `x'_nofin: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if i_fin!=1 , cluster(section_id)
		 
		sum `x' if i_fin!=1 & female==1, d
        local mean_f = r(mean)
        sum `x' if i_fin!=1 & female==0, d
        local mean_m = r(mean)
			
		sum `x' if i_fin!=1, d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_nofin, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace


		

}

	 
	 esttab mgr2_v3_main mgr2_v3_controls ///
	using "${output}/tables/Table_A11.tex", replace ///
	 keep(femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(mean_f mean_m r2 N classfe, ///
     label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
     "Class x Year x Female FE") ///
     fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("\shortstack{Main Result}"  ///
	 "\shortstack{Additional Controls}") ///
	 mgroups("Senior Manager", pattern(1 0) ///
	 prefix(\multicolumn{@span}{c}{) suffix(}) ///
	 span erepeat(\cmidrule(lr){@span}))booktabs f noomitted nobaselevel

}

* Table A12: Effect of Female Peers on Senior Manager in Female-Friendly Firms: Alternative Measures
if `p18'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
rename gd_fem_pct_d_totalpay gd_fem_d_tot
rename gd_sr_mgr_fem_pct_d_totalpay gd_mgr_fem_d_tot

preserve
bys firm_id_LI: keep if _n==1
foreach var in fgb_rating paid_weeks board_women_pct gd_fem_d_tot gd_mgr_fem_d_tot{
	
	if "`var'"=="paid_weeks" | "`var'"=="board_women_pct"{
	sum `var', d
	}
	if "`var'"=="fgb_rating"{
	sum `var' [aweight=fgb_reviews], d
	}
	if "`var'"=="gd_fem_d_tot" | "`var'"=="gd_mgr_fem_d_tot" {
	sum `var' [aweight=gd_reviews], d
	}
	gen `var'_med = (`var'>=`r(p50)')
	replace `var'_med = . if `var'==.
	replace `var'_med = 0 if employed == 0
	gen `var'_nomed = 1-`var'_med 
}
keep firm_id_LI fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med
tempfile median
save `median', replace 
restore

merge m:1 firm_id_LI using `median'
drop _merge


local fam_vars ihs_stars_med ihs_opportunities_med ihs_flexibility_med ihs_enrichment_med ihs_compensation_med ///
			ihs_family_med ihs_culture_med ///
			fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
	
	gen `var'_nomgr = (`var'==0 & mgr2_v3==1)
	replace `var'_nomgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge 

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay


preserve	 
*COEFPLOT WITH INDICES
bys firm_id_LI: keep if _n==1



foreach x in size_LI ///
			gd_totalpay gd_totalpaysenior_manager ///
			gd_fem_pct_totpay gd_sr_mgr_fem_pct_totpay ///
			fgb_rating paid_weeks board_women_pct{
			
			egen z_`x' = std(`x')
}

gen weights = ihs_ratings_count + fgb_reviews

keep firm_id_LI z_size_LI top_100_firm ///
			z_gd_totalpay z_gd_totalpaysenior_manager ///
			z_gd_fem_pct_totpay z_gd_sr_mgr_fem_pct_totpay ///
			ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture  ///
			z_fgb_rating z_paid_weeks z_board_women_pct weights

tempfile firm_ihs
save `firm_ihs', replace 
 
restore

merge m:1 firm_id_LI using `firm_ihs'
drop _merge

rename z_gd_totalpaysenior_manager z_gd_totalpaysr_manager
rename z_gd_sr_mgr_fem_pct_totpay z_gd_sr_mgr_fem_pct_tot


	 
	 
*ALTERNATIVE MEASURE OF FEMALE FRIENDLINESS	
 
foreach x in fgb_rating_med_mgr paid_weeks_med_mgr board_women_pct_med_mgr ///
			gd_fem_d_tot_med_mgr gd_mgr_fem_d_tot_med_mgr ///
			fgb_rating_med_nomgr paid_weeks_med_nomgr board_women_pct_med_nomgr ///
			gd_fem_d_tot_med_nomgr gd_mgr_fem_d_tot_med_nomgr ///
			{
		if "`x'"=="fgb_rating_med_mgr" | "`x'"=="fgb_rating_med_nomgr"{
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=fgb_reviews], cluster(section_id)
		 
			sum `x' [aweight=fgb_reviews] if female==1, d
            local mean_f = r(mean)
            sum `x' [aweight=fgb_reviews] if female==0, d
            local mean_m = r(mean)
			
			sum `x' [aweight=fgb_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="paid_weeks_med_mgr" | "`x'"=="paid_weeks_med_nomgr" ///
		| "`x'"=="board_women_pct_med_mgr" | "`x'"=="board_women_pct_med_nomgr"{
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
			sum `x' if female==1, d
            local mean_f = r(mean)
            sum `x' if female==0, d
            local mean_m = r(mean)
			
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}

		if "`x'"=="gd_fem_d_tot_med_mgr" | "`x'"=="gd_fem_d_tot_med_nomgr" ///
		| "`x'"=="gd_mgr_fem_d_tot_med_mgr" | "`x'"=="gd_mgr_fem_d_tot_med_nomgr" {
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=gd_reviews], cluster(section_id)
		 
			sum `x' [aweight=gd_reviews] if female==1, d
            local mean_f = r(mean)
            sum `x' [aweight=gd_reviews] if female==0, d
            local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews], d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			}
	
}
esttab fgb_rating_med_mgr fgb_rating_med_nomgr paid_weeks_med_mgr paid_weeks_med_nomgr ///
			board_women_pct_med_mgr board_women_pct_med_nomgr ///
	 using "${output}/tables/Table_A12.tex", replace ///
	 keep(femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(mean_f mean_m r2 N classfe, ///
     label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
     "Class x Year x Female FE") ///
     fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("Above Median" ///
	 "Below Median" ///
	 "Above Median" ///
	 "Below Median" ///
	 "Above Median" ///
	 "Below Median") ///
	 mgroups("Female-Friendly Firm (FGB)" ///
	 "Firm with Paid Maternity Leave" ///
	 "Firm with \% Female Board Members", pattern(1 0 1 0 1 0) ///
	 prefix(\multicolumn{@span}{c}{) suffix(}) ///
	 span erepeat(\cmidrule(lr){@span}))booktabs f noomitted nobaselevel
	 

}

* Table A13: Effect of Female Peers on GPA during MBA
if `p19'==1{
use "${data}/raw/analysis_sections_fake.dta", clear
lab var female_dummy "Female"
lab var female_share "Female share" 

if "`c(username)'"=="mvh4"{
gen femaleshare_male = female_share * (1-female_dummy)
gen femaleshare_female = female_share* female_dummy

lab var femaleshare_male "Female share \(\times\) Male" 
lab var femaleshare_female "Female share \(\times\) Female" 

local missings top20 pre_MBA_mgr2_v3 finance

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	
rename race_d6 white


local variables white US_citizen_dummy pre_MBA_any_mgr_v3 pre_MBA_mgr2_v3 consulting finance other
foreach x in `variables'{
	bys section_id: egen m_`x' = mean(`x')
}

}

local controls i.female_dummy ///
				i.Class##i.female_dummy ///
				top20##i.female_dummy ///
				top20_m##i.female_dummy ///
				pre_MBA_mgr2_v3##i.female_dummy ///
				i.pre_MBA_mgr2_v3_m##i.female_dummy ///
				finance##i.female_dummy ///
				i.finance_m##i.female_dummy ///
				c.m_pre_MBA_any_mgr_v3 ///
				c.m_pre_MBA_mgr2_v3 ///
				c.m_finance ///
				c.m_consulting ///
				c.m_other ///
				c.m_white ///
				c.m_US_citizen_dummy
			
*local controls c.approx_age##c.approx_age i.female_dummy i.preMBA_wage_d i.Class i.preMBA_industry c.GMAT i.race i.citizenship `controlslist'

egen pct_course_noncore_other = rowmean(pct_course_noncore_acct pct_course_noncore_blaw pct_course_noncore_decs pct_course_noncore_dsgn pct_course_noncore_entr pct_course_noncore_hema pct_course_noncore_kaci pct_course_noncore_kiei pct_course_noncore_kmci pct_course_noncore_kppi pct_course_noncore_mecn pct_course_noncore_medm pct_course_noncore_real pct_course_noncore_strt pct_course_noncore_tech)

local classes core_gpa gpa ///
				pct_noncore_finc pct_course_noncore_intl pct_course_noncore_mgmt pct_course_noncore_mktg ///
				pct_course_noncore_mors pct_course_noncore_opns pct_course_noncore_seek pct_course_noncore_other
				
//gpa_finc course_noncore_finc
*---------------------*
* Analysis on classes *
*---------------------*
eststo clear

eststo clear
foreach x of local classes{

		quietly eststo `x'_ag: reg `x' femaleshare_male femaleshare_female `controls', cluster(section_id)
		
		test femaleshare_male = femaleshare_female
		local p_value = r(p)
		
		sum `x' if female_dummy==1, d
		local mean_f = r(mean)
		sum `x' if female_dummy==0, d
		local mean_m = r(mean)
		
		eststo `x'_ag, addscalars(mean_f `mean_f' mean_m `mean_m' p_value `p_value')
		estadd local classfe "Yes" , replace
		
		
}

esttab gpa_ag core_gpa_ag   ///
using "${output}/tables/Table_A13.tex", replace ///
 s(mean_f mean_m r2 N classfe, ///
 label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
 "Class x Female FE") ///
 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
 keep(femaleshare_female) ///
 star(* .10 ** .05 *** .01)  se r2 label interaction(" $\times$ ") /// 
 mtitles("Overall GPA" ///
 "\shortstack{Core Classes \\ GPA}") ///
  booktabs f noomitted nobaselevel
}

* Table A14: Effect of Female Peers on Choice of Elective Classes
if `p20'==1{
use "${data}/raw/analysis_sections_fake.dta", clear
lab var female_dummy "Female"
lab var female_share "Female share" 



local controls i.female_dummy ///
				i.Class##i.female_dummy ///
				top20##i.female_dummy ///
				top20_m##i.female_dummy ///
				pre_MBA_mgr2_v3##i.female_dummy ///
				i.pre_MBA_mgr2_v3_m##i.female_dummy ///
				finance##i.female_dummy ///
				i.finance_m##i.female_dummy ///
				c.m_pre_MBA_any_mgr_v3 ///
				c.m_pre_MBA_mgr2_v3 ///
				c.m_finance ///
				c.m_consulting ///
				c.m_other ///
				c.m_white ///
				c.m_US_citizen_dummy
			
*local controls c.approx_age##c.approx_age i.female_dummy i.preMBA_wage_d i.Class i.preMBA_industry c.GMAT i.race i.citizenship `controlslist'

egen pct_course_noncore_other = rowmean(pct_course_noncore_acct pct_course_noncore_blaw pct_course_noncore_decs pct_course_noncore_dsgn pct_course_noncore_entr pct_course_noncore_hema pct_course_noncore_kaci pct_course_noncore_kiei pct_course_noncore_kmci pct_course_noncore_kppi pct_course_noncore_mecn pct_course_noncore_medm pct_course_noncore_real pct_course_noncore_strt pct_course_noncore_tech)

local classes core_gpa gpa ///
				pct_noncore_finc pct_course_noncore_intl pct_course_noncore_mgmt pct_course_noncore_mktg ///
				pct_course_noncore_mors pct_course_noncore_opns pct_course_noncore_seek pct_course_noncore_other
				
//gpa_finc course_noncore_finc
*---------------------*
* Analysis on classes *
*---------------------*

eststo clear
foreach x of local classes{

		quietly eststo `x'_ag: reg `x' femaleshare_male femaleshare_female `controls', cluster(section_id)
		
		test femaleshare_male = femaleshare_female
		local p_value = r(p)
		
		sum `x' if female_dummy==1, d
		local mean_f = r(mean)
		sum `x' if female_dummy==0, d
		local mean_m = r(mean)
		
		eststo `x'_ag, addscalars(mean_f `mean_f' mean_m `mean_m' p_value `p_value')
		estadd local classfe "Yes" , replace
		
		
}


 
esttab pct_noncore_finc_ag pct_course_noncore_intl_ag pct_course_noncore_mgmt_ag pct_course_noncore_mktg_ag ///
pct_course_noncore_mors_ag pct_course_noncore_opns_ag pct_course_noncore_seek_ag pct_course_noncore_other_ag   ///
using "${output}/tables/Table_A14.tex", replace ///
 s(mean_f mean_m r2 N classfe, ///
 label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
 "Class x Female FE") ///
 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
 keep(femaleshare_female) ///
 star(* .10 ** .05 *** .01)  se r2 label interaction(" $\times$ ") /// 
 mtitles("Finance" "\shortstack{International \\ Business}" "Management" "Marketing" "\shortstack{Management and \\ Organizations}" "Operations" "\shortstack{Social \\ Enterprise}" "Other") ///
  booktabs f noomitted nobaselevel
}

* Table A15: Effect of Female Peers on First Post-MBA Placement
if `p21'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

gen log_gd_i_totalpay = ln(gd_i_totalpay+1)
gen log_gd_i_bonuspay = ln(gd_i_bonuspay+1)
gen log_gd_i_basepay = ln(gd_i_basepay+1)

replace gd_i_basepay = gd_i_basepay/1000
replace gd_i_bonuspay = gd_i_bonuspay/1000
replace gd_i_totalpay = gd_i_totalpay/1000

preserve
collapse femaleshare_ind = female , by(i_categorical)
keep i_categorical femaleshare_ind
tempfile femaleshare_ind
save `femaleshare_ind', replace
restore

merge m:1 i_categorical using `femaleshare_ind'
drop _merge
replace gd_totalpay = gd_totalpay/1000

*POOLED REGRESSIONS
foreach x in mgr2_v3 i_male ihs_stars_med size_LI gd_totalpay ///
			{

		
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female  ///
			 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 if year_since_grad==1, cluster(section_id)
			
			sum `x' if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace

	
	
		if "`x'"=="paid_weeks" ///
			| "`var'"=="firm_flexible" | "`x'" == "fam_friendly_index2" ///
			| "`x'" == "board_women_pct" | "`x'" == "fam_friendly_index2_m_r" {
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female if year_since_grad==1, cluster(section_id)
		 
			sum `x' if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "gd_i_basepay" | "`x'" == "gd_i_basepay_imp" ///
			| "`x'" == "gd_i_totalpay" | "`x'" == "gd_i_totalpay_imp" ///
			| "`x'" == "gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_totalpay" | "`x'" == "log_gd_i_bonuspay" ///
			| "`x'" == "log_gd_i_basepay" {
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 [aweight=gd_i_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean) 
			
			sum `x' [aweight=gd_i_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_i_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace

		eststo `x'_i_sm: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			  c.m_pre_any_mgr_v3 ///
             c.m_pre_mgr2_v3 ///
             c.m_pre_i_fin ///
             c.m_pre_i_cons ///
             c.m_pre_i_oth ///
             c.m_pre_PL2 ///
             c.m_white ///
             c.m_foreign ///
		 i.mgr_cat_broad##i.female [aweight=gd_i_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=gd_i_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_i_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_i_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i_sm, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			estadd local mgr_cat_fe "Yes" , replace
		}
		
		
		if "`x'" == "gd_fem_pct_d_basepay" | "`x'" == "gd_sr_mgr_fem_pct_d_base" ///
			| "`x'" == "gd_fem_share_emp" | "`x'" == "gd_fem_share_sr_mgr" ///
			| "`x'" == "gd_basepay" | "`x'" == "gd_basepaysenior_manager" ///
			| "`x'" == "gd_totalpay" | "`x'" == "gd_totalpaysenior_manager" ///
			| "`x'" == "gd_fem_pct_totpay" | "`x'" == "gd_sr_mgr_fem_pct_totpay"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=gd_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=gd_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=gd_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=gd_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=gd_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'" == "ihs_stars" | "`x'" == "ihs_stars_m_r" | "`x'" == "ihs_stars_m_r_mgr" | "`x'" == "n_ihs_stars_m_r_mgr" ///
			| "`x'" == "ihs_stars_l" | "`x'" == "ihs_stars_u" ///
			| "`x'" == "ihs_stars_q1" | "`x'" == "ihs_stars_q2" | "`x'" == "ihs_stars_q3" | "`x'" == "ihs_stars_q4" ///
			| "`x'" == "ihs_stars_med" | "`x'" == "ihs_stars_med_mgr" | "`x'" == "ihs_stars_no_med_mgr" ///
			| "`x'" == "ihs_stars_q1_mgr" | "`x'" == "ihs_stars_q2_mgr" ///
			| "`x'" == "ihs_stars_q3_mgr" | "`x'" == "ihs_stars_q4_mgr" ///
			| "`x'" == "ihs_stars_q1_male_mgr2_v3" | "`x'" == "ihs_stars_q2_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_male_mgr2_v3" | "`x'" == "ihs_stars_q4_male_mgr2_v3" ///
			| "`x'" == "ihs_stars_q1_fem_mgr2_v3" | "`x'" == "ihs_stars_q2_fem_mgr2_v3" ///
			| "`x'" == "ihs_stars_q3_fem_mgr2_v3" | "`x'" == "ihs_stars_q4_fem_mgr2_v3" ///
			| "`x'" == "ihs_remote" | "`x'" == "ihs_employer" | "`x'" == "ihs_genderequal" ///
			| "`x'" == "ihs_familysupport" | "`x'" == "ihs_femaleleader" | "`x'" == "ihs_flexible" ///
			| "`x'" == "ihs_learning" | "`x'" == "ihs_mgmtopp" | "`x'" == "ihs_ML" | "`x'" == "ihs_paidtimeoff" ///
			| "`x'" == "ihs_salarysatisfy" | "`x'" == "ihs_belonging" | "`x'" == "ihs_social" ///
			| "`x'" == "ihs_sponsorship" | "`x'" == "ihs_diversity" | "`x'" == "ihs_people" ///
			| "`x'" == "ihs_wellness" | "`x'" == "ihs_dads_have_pl" | "`x'" == "ihs_received" ///
			| "`x'" == "ihs_growth" | "`x'" == "ihs_support" | "`x'" == "ihs_agree" ///
			| "`x'" == "ihs_opportunities_med" | "`x'" == "ihs_flexibility_med" | "`x'" == "ihs_enrichment_med" ///
			| "`x'" == "ihs_compensation_med" | "`x'" == "ihs_family_med" | "`x'" == "ihs_culture_med"{
			
		eststo `x'_w: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=ihs_ratings_count] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_w, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		

		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=ihs_ratings_count] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=ihs_ratings_count] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=ihs_ratings_count] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=ihs_ratings_count] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="fgb_rating"{
				eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female [aweight=fgb_reviews] if year_since_grad==1, cluster(section_id)
			
			sum `x' [aweight=fgb_reviews] if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' [aweight=fgb_reviews] if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' [aweight=fgb_reviews] if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}
		
		if "`x'"=="size_LI" | "`x'"=="small" | "`x'"=="medium" | ///
			"`x'"=="big" | "`x'"=="top_100_firm" {
			
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if year_since_grad==1, cluster(section_id)
			
			sum `x' if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
		
		eststo `x'_i: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 i.i_categorical##i.female if year_since_grad==1, cluster(section_id)
			
			sum `x' if female==1 & year_since_grad==1, d
			local mean_f = r(mean)
			sum `x' if female==0 & year_since_grad==1, d
			local mean_m = r(mean)
			
			sum `x' if year_since_grad==1, d
			local mean = r(mean)
			local sd = r(sd)
			test femaleshare_male = femaleshare_female
			local p_value = r(p)
			eststo `x'_i, addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
		}

}



esttab mgr2_v3 i_male ihs_stars_med_w size_LI gd_totalpay_w ///
	using "${output}/tables/Table_A15.tex", replace ///
	 keep(femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(mean_f mean_m r2 N classfe, ///
	 label("Female Mean" "Male Mean" "\(R^2\)" "N" ///
	 "Class x Female FE") ///
	 fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("\shortstack{Senior-Level \\ Manager}" ///
	 "\shortstack{Male-Dominated \\ Industries}" ///
	 "\shortstack{Female-Friendly \\ Firms}" ///
	 "\shortstack{Number of \\ Employees}" ///
	 "\shortstack{Firm Annual \\ Compensation \\ ('000s)}") booktabs f noomitted nobaselevel
}

* Table B1: Coverage Rate of Alumni Directory, 2000-2010 Records
if `p22'==1{
*------------------*
* MATCH STATISTICS *
*------------------*
cap file close myfile
file open myfile using "${output}/tables/Table_B1.tex", write replace
file write myfile "&\multicolumn{2}{c}{Overall}&\multicolumn{2}{c}{Male}&\multicolumn{2}{c}{Female} \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}" _n ///
    "&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share}&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share}&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share} \\ \cmidrule(c){2-7}" _n ///
	

	file write myfile " & & & & & &  \\" _n
	
use "${data}/raw/admin_section_data_allyears_fake.dta",clear
drop if Class==2009 
keep if Class >= 2000 & Class <=2010
collapse (sum) females = females_section males = males_section total = total_section


scalar share_miss = 1
local share_miss: di %9.3f scalar(share_miss)
levelsof total, local(n) 
scalar all_units = `n'
local all_units: di %9.0f scalar(all_units)

scalar share_miss_m = 1
local share_miss_m: di %9.3f scalar(share_miss_m)
levelsof males, local(n) 
scalar all_units_m = `n'
local all_units_m: di %9.0f scalar(all_units_m)

scalar share_miss_f = 1
local share_miss_f: di %9.3f scalar(share_miss_f)
levelsof females, local(n) 
scalar all_units_f = `n'
local all_units_f: di %9.0f scalar(all_units_f)

file write myfile "Admin Data & `all_units' & `share_miss' & `all_units_m' & `share_miss_m' & `all_units_f' & `share_miss_f' \\" _n

use "${data}/raw/alumni_names_gender_fake.dta",clear
drop if Class==2009 
keep if Class >= 2000 & Class <=2010
count
scalar units = `r(N)'
local units: di %9.0f scalar(units)
scalar share_miss = `units'/`all_units'
local share_miss: di %9.3f scalar(share_miss)

count if female ==0
scalar units_m = `r(N)'
local units_m: di %9.0f scalar(units_m)
scalar share_miss_m = `units_m'/`all_units_m'
local share_miss_m: di %9.3f scalar(share_miss_m)

count if female==1
scalar units_f = `r(N)'
local units_f: di %9.0f scalar(units_f)
scalar share_miss_f = `units_f'/`all_units_f'
local share_miss_f: di %9.3f scalar(share_miss_f)

file write myfile "Alumni Directory &  `units' & `share_miss' & `units_m' & `share_miss_m' & `units_f' & `share_miss_f' \\" _n


file write myfile "\bottomrule" _n 
file close myfile

}

* Table B2: Coverage Rate of Alumni Directory Records by Class, 2000-2010
if `p23'==1{
*------------------*
* MATCH STATISTICS *
*------------------*


cap file close myfile
file open myfile using "${output}/tables/Table_B2.tex", write replace
file write myfile "&\multicolumn{2}{c}{Overall}&\multicolumn{2}{c}{Male}&\multicolumn{2}{c}{Female} \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}" _n ///
    "&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share}&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share}&\multicolumn{1}{c}{N}&\multicolumn{1}{c}{Non-Missing Share} \\ \cmidrule(c){2-7}" _n ///
	
foreach y in 00 01 02 03 04 05 06 07 08 10 {

	*file write myfile " & & & & & &  \\" _n
	file write myfile "\multicolumn{5}{l}{\textbf{Cohort 20`y'}} \\" _n
	

use "${data}/raw/admin_section_data_allyears_fake.dta",clear
collapse (sum) females = females_section males = males_section total = total_section, by(Class)

keep if Class == 20`y'

scalar share_miss = 1
local share_miss: di %9.3f scalar(share_miss)
levelsof total, local(n) 
scalar all_units = `n'
local all_units: di %9.0f scalar(all_units)

scalar share_miss_m = 1
local share_miss_m: di %9.3f scalar(share_miss_m)
levelsof males, local(n) 
scalar all_units_m = `n'
local all_units_m: di %9.0f scalar(all_units_m)

scalar share_miss_f = 1
local share_miss_f: di %9.3f scalar(share_miss_f)
levelsof females, local(n) 
scalar all_units_f = `n'
local all_units_f: di %9.0f scalar(all_units_f)

file write myfile "Admin Data & `all_units' & `share_miss' & `all_units_m' & `share_miss_m' & `all_units_f' & `share_miss_f' \\" _n

use "${data}/raw/alumni_names_gender_fake.dta",clear
keep if Class == 20`y'

count
scalar units = `r(N)'
local units: di %9.0f scalar(units)
scalar share_miss = `units'/`all_units'
local share_miss: di %9.3f scalar(share_miss)

count if female ==0
scalar units_m = `r(N)'
local units_m: di %9.0f scalar(units_m)
scalar share_miss_m = `units_m'/`all_units_m'
local share_miss_m: di %9.3f scalar(share_miss_m)

count if female==1
scalar units_f = `r(N)'
local units_f: di %9.0f scalar(units_f)
scalar share_miss_f = `units_f'/`all_units_f'
local share_miss_f: di %9.3f scalar(share_miss_f)

file write myfile "Alumni Directory &  `units' & `share_miss' & `units_m' & `share_miss_m' & `units_f' & `share_miss_f' \\" _n

}

file write myfile "\bottomrule" _n 
file close myfile


}

* Figure B1: Correlation Across Female-Friendliness Measures + Call code in R
if `p24'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
rename gd_fem_pct_d_totalpay gd_fem_d_tot
rename gd_sr_mgr_fem_pct_d_totalpay gd_mgr_fem_d_tot

preserve
bys firm_id_LI: keep if _n==1
foreach var in fgb_rating paid_weeks board_women_pct gd_fem_d_tot gd_mgr_fem_d_tot{
	
	if "`var'"=="paid_weeks" | "`var'"=="board_women_pct"{
	sum `var', d
	}
	if "`var'"=="fgb_rating"{
	sum `var' [aweight=fgb_reviews], d
	}
	if "`var'"=="gd_fem_d_tot" | "`var'"=="gd_mgr_fem_d_tot" {
	sum `var' [aweight=gd_reviews], d
	}
	gen `var'_med = (`var'>=`r(p50)')
	replace `var'_med = . if `var'==.
	replace `var'_med = 0 if employed == 0
	gen `var'_nomed = 1-`var'_med 
}
keep firm_id_LI fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med
tempfile median
save `median', replace 
restore

merge m:1 firm_id_LI using `median'
drop _merge


local fam_vars ihs_stars_med ihs_opportunities_med ihs_flexibility_med ihs_enrichment_med ihs_compensation_med ///
			ihs_family_med ihs_culture_med ///
			fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
	
	gen `var'_nomgr = (`var'==0 & mgr2_v3==1)
	replace `var'_nomgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge 

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay


	 
*COEFPLOT WITH INDICES
bys firm_id_LI: keep if _n==1



foreach x in size_LI ///
			gd_totalpay gd_totalpaysenior_manager ///
			gd_fem_pct_totpay gd_sr_mgr_fem_pct_totpay ///
			fgb_rating paid_weeks board_women_pct{
			
			egen z_`x' = std(`x')
}

gen weights = ihs_ratings_count + fgb_reviews

keep firm_id_LI z_size_LI top_100_firm ///
			z_gd_totalpay z_gd_totalpaysenior_manager ///
			z_gd_fem_pct_totpay z_gd_sr_mgr_fem_pct_totpay ///
			ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture  ///
			z_fgb_rating z_paid_weeks z_board_women_pct weights

tempfile firm_ihs
save `firm_ihs', replace 

foreach x in ihs_stars{
			
			egen z_`x' = std(`x')
}

keep z_ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture ///
			z_fgb_rating z_paid_weeks z_board_women_pct weights
order z_ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture z_fgb_rating z_paid_weeks z_board_women_pct weights
			
lab var z_ihs_stars "Female-Friendly Rating (IHS)"
lab var ihs_opportunities  "Gender Equal Opportunities"     
lab var ihs_flexibility  "Work Schedule Flexibility"
lab var ihs_enrichment  "Professional Enrichment" 
lab var ihs_compensation "Fair Compensation"
lab var ihs_family  "Family Friendliness" 
lab var ihs_culture  "Workplace Culture"
lab var z_fgb_rating "Female-Friendly Rating (FGB)"
lab var z_paid_weeks "Number of Weeks of Maternity Leave"
lab var z_board_women_pct "Percentage of Women in the Board"

lab var weights "Firm Level Weights"
	 
save "${data}/analysis/IHS_correlation_index_data_R.dta", replace
 
*Need to call code in R "IHS_correlations.R"
rscript using "${code}/IHS_correlations.R", args("${data}/analysis/" "${output}/graphs/")

}

* Figure B2: Female-Friendly Firms Representation by Industry
if `p25'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay
gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

*create manager + family friendly index + male dom
gen a_m_fam_fr_male_mgr2_v3 = (ihs_stars_med==1 & mgr2_v3==1 & i_male==1)
replace a_m_fam_fr_male_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_male==.

gen b_m_fam_fr_male_mgr2_v3 = (ihs_stars_med==0 & mgr2_v3==1 & i_male==1)
replace b_m_fam_fr_male_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_male==.

gen a_m_fam_fr_female_mgr2_v3 = (ihs_stars_med==1 & mgr2_v3==1 & i_female==1)
replace a_m_fam_fr_female_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_female==.

gen b_m_fam_fr_female_mgr2_v3 = (ihs_stars_med==0 & mgr2_v3==1 & i_female==1)
replace b_m_fam_fr_female_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_female==.

*************************************
* DESCRIPTIVE TABLE FOR IHS *
*************************************

bys firm_id_LI: keep if _n==1
replace gd_totalpay = gd_totalpay/1000
local variables size_LI gd_fem_share_emp gd_fem_share_sr_mgr gd_totalpay paid_weeks board_women_pct //gd_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_basepay
lab var size_LI "Number of Employees"
lab var gd_fem_share_emp "Female Share of Employees (Glassdoor)"
lab var gd_fem_share_sr_mgr "Female Share of Sr. Managers (Glassdoor)"
lab var gd_totalpay "Total Annual Compensation ('000s)"
lab var paid_weeks "Paid Maternity Leave"
lab var board_women_pct "\% Female Board Members"
lab var gd_fem_pct_d_basepay "Gender Pay Gap"
lab var gd_sr_mgr_fem_pct_d_basepay "Gender Pay Gap for Sr. Managers"


 
collapse ihs_stars_med , by(i_categorical)

graph bar (asis) ihs_stars_med ,  over(i_categorical, sort(1) descending relabel(1 "Finance" 2 "Consulting" 3 "Cons. Goods" 4 "Healthcare" 5 "Tech" 6 "Other")) ///
 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) ///
 ytitle("Proportion of Female-Friendly Firms", size(small)) bar(1,color("25 81 144"))
graph export "${output}/graphs/Figure_B2.png", replace		


}

* Table B3: Female-Friendly Firms versus Non-Female-Friendly Firms
if `p26'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr = (external==1 & mgr2_v3==1)
replace external_mgr=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay

*create manager + family friendly index + male dom
gen a_m_fam_fr_male_mgr2_v3 = (ihs_stars_med==1 & mgr2_v3==1 & i_male==1)
replace a_m_fam_fr_male_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_male==.

gen b_m_fam_fr_male_mgr2_v3 = (ihs_stars_med==0 & mgr2_v3==1 & i_male==1)
replace b_m_fam_fr_male_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_male==.

gen a_m_fam_fr_female_mgr2_v3 = (ihs_stars_med==1 & mgr2_v3==1 & i_female==1)
replace a_m_fam_fr_female_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_female==.

gen b_m_fam_fr_female_mgr2_v3 = (ihs_stars_med==0 & mgr2_v3==1 & i_female==1)
replace b_m_fam_fr_female_mgr2_v3=. if ihs_stars_med==. | mgr2_v3==. | i_female==.

*************************************
* DESCRIPTIVE TABLE FOR IHS *
*************************************

sort firm_id_LI, stable
by firm_id_LI: keep if _n==1

replace gd_totalpay = gd_totalpay/1000
local variables size_LI gd_fem_share_emp gd_fem_share_sr_mgr gd_totalpay paid_weeks board_women_pct //gd_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_basepay
lab var size_LI "Number of Employees"
lab var gd_fem_share_emp "Female Share of Employees (Glassdoor)"
lab var gd_fem_share_sr_mgr "Female Share of Sr. Managers (Glassdoor)"
lab var gd_totalpay "Total Annual Compensation ('000s)"
lab var paid_weeks "Paid Maternity Leave"
lab var board_women_pct "\% Female Board Members"
lab var gd_fem_pct_d_basepay "Gender Pay Gap"
lab var gd_sr_mgr_fem_pct_d_basepay "Gender Pay Gap for Sr. Managers"

estpost sum `variables'
est store A

estpost sum `variables' if ihs_stars_med==1
est store B

estpost sum `variables' if ihs_stars_med==0
est store C

estpost ttest `variables', by(ihs_stars_med) 
est store D
estadd matrix mean = e(b)
estadd matrix sd = e(p)


esttab B C D using "${output}/tables/Table_B3.tex", replace cells(mean(fmt(2) star) sd(par))  star(* .10 * .05 ** .01)  ///
 label nonum collabels(none) booktabs f wide mtitles("Female-Friendly" "Non-Female-Friendly" "Difference") 



}

* Figure B3: Share of Senior Managers by Industry in the First Five Years Post-MBA
if `p27'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }

	
keep if year_since_grad>=1 & year_since_grad<=5


sort linkedin_id year_since_grad



*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)

preserve
collapse mgr2_v3 , by(i_categorical)

graph bar (asis) mgr2_v3 ,  over(i_categorical, sort(1) descending relabel(1 "Finance" 2 "Consulting" 3 "Cons. Goods" 4 "Healthcare" 5 "Tech" 6 "Other")) ///
 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) ///
 ytitle("Proportion of Senior Managers", size(small)) bar(1,color("25 81 144"))
graph export "${output}/graphs/Figure_B3a.png", replace		
restore

encode companysize_LI, gen(size_LI_cat)
reg mgr2_v3 i.size_LI_cat
predict mgr2_v3_adj, resid 
replace mgr2_v3_adj = mgr2_v3_adj + _b[_cons]

collapse mgr2_v3_adj , by(i_categorical)

graph bar (asis) mgr2_v3_adj ,  over(i_categorical, sort(1) descending relabel(1 "Finance" 2 "Consulting" 3 "Cons. Goods" 4 "Healthcare" 5 "Tech" 6 "Other")) ///
 plotregion(fcolor(white)) ylabel(0(.1).5) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) ///
 ytitle("Proportion of Senior Managers" "Adjusted for Firm Size", size(small)) bar(1,color("25 81 144"))
graph export "${output}/graphs/Figure_B3b.png", replace	
	
}

* Figure B4: Average Org Level by Management Level and Industry 
if `p28'==1{


**** Direct Reports 
use "${data}/raw/org_manager_pe_fake.dta", clear

* Drop the Undocumented Titles
drop if management_level=="Undoc"



reg manager_org_level i.mgmt_level i.industry_cat i.size_cat
margins mgmt_level /*Adjusted Means*/


* Org Level - by Industry and Management Level (Smaller Fonts)
graph bar (mean) manager_org_level if li_industry=="Consulting", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Consulting", size(small)) ///
    name(g_org_consulting, replace)

graph bar (mean) manager_org_level if li_industry=="Consumer Goods", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Consumer Goods", size(small)) ///
    name(g_org_consumer, replace)

graph bar (mean) manager_org_level if li_industry=="Finance", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Finance", size(small)) ///
    name(g_org_finance, replace)

graph bar (mean) manager_org_level if li_industry=="Technology", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Technology", size(small)) ///
    name(g_org_tech, replace)

graph bar (mean) manager_org_level if li_industry=="Healthcare", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Healthcare", size(small)) ///
    name(g_org_health, replace)

graph bar (mean) manager_org_level if li_industry=="Other", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Org Level", size(small)) ///
    title("Other", size(small)) ///
    name(g_org_other, replace)

* Combine the Org Level Graphs
graph combine g_org_consulting g_org_consumer g_org_finance ///
              g_org_tech g_org_health g_org_other, ///
              col(3) iscale(.8) imargin(tiny) ycommon ///
              title("Average Org Level by Management Level and Industry", size(small))

* Export to PDF
graph export "${output}/graphs/Figure_B4.pdf", replace
 

}

* Figure B5: Average Number of Direct Reports by Management Level and Industry 
if `p29'==1{

**** Direct Reports 
use "${data}/raw/org_manager_pe_fake.dta", clear

* Drop the Undocumented Titles
drop if management_level=="Undoc"


/* Check Regressions */
reg manager_direct_report_ct i.mgmt_level i.industry_cat i.size_cat
margins mgmt_level /*Adjusted Means*/


/* BAR GRAPHS BY INDUSTRY Reports*/
* Direct Reports 
* Individual Graphs with Smaller Fonts
graph bar (mean) manager_direct_report_ct if li_industry=="Consulting", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Consulting", size(small)) ///
    name(g_consulting, replace)

graph bar (mean) manager_direct_report_ct if li_industry=="Consumer Goods", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Consumer Goods", size(small)) ///
    name(g_consumer, replace)

graph bar (mean) manager_direct_report_ct if li_industry=="Finance", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Finance", size(small)) ///
    name(g_finance, replace)

graph bar (mean) manager_direct_report_ct if li_industry=="Technology", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Technology", size(small)) ///
    name(g_tech, replace)

graph bar (mean) manager_direct_report_ct if li_industry=="Healthcare", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Healthcare", size(small)) ///
    name(g_health, replace)

graph bar (mean) manager_direct_report_ct if li_industry=="Other", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Direct Reports", size(small)) ///
    title("Other", size(small)) ///
    name(g_other, replace)

* Combine the Graphs with a Smaller Title Font
graph combine g_consulting g_consumer g_finance ///
              g_tech g_health g_other, ///
              col(3) iscale(.8) imargin(tiny) ycommon ///
              title("Average Number of Direct Reports by Management Level and Industry", size(small))

graph export "${output}/graphs/Figure_B5.pdf", replace

}

* Figure B6: Average Number of Indirect Reports by Management Level and Industry 
if `p30'==1{

/* Analysis */
	
use "${data}/raw/org_manager_pe_fake.dta", clear

* Drop the Undocumented Titles
drop if management_level=="Undoc"

sort firm_id managername managertitle managerliprofileurl

merge 1:1 firm_id managername managertitle managerliprofileurl using "${data}/raw/indirect_reports_fake.dta"

drop if _merge==2



/* BAR GRAPHS BY INDUSTRY Reports*/
* Direct Reports 
* Individual Graphs with Smaller Fonts
graph bar (mean) indirectreports if li_industry=="Consulting", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Consulting", size(small)) ///
    name(g_consulting, replace)

graph bar (mean) indirectreports if li_industry=="Consumer Goods", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Consumer Goods", size(small)) ///
    name(g_consumer, replace)

graph bar (mean) indirectreports if li_industry=="Finance", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Finance", size(small)) ///
    name(g_finance, replace)

graph bar (mean) indirectreports if li_industry=="Technology", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Technology", size(small)) ///
    name(g_tech, replace)

graph bar (mean) indirectreports if li_industry=="Healthcare", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Healthcare", size(small)) ///
    name(g_health, replace)

graph bar (mean) indirectreports if li_industry=="Other", ///
    over(management_level, sort(1) label(labsize(vsmall))) ///
    blabel(bar, format(%3.1f) size(small)) ///
    ytitle("Average Indirect Reports", size(small)) ///
    title("Other", size(small)) ///
    name(g_other, replace)

* Combine the Graphs with a Smaller Title Font
graph combine g_consulting g_consumer g_finance ///
              g_tech g_health g_other, ///
              col(3) iscale(.8) imargin(tiny) ycommon ///
              title("Average Number of Indirect Reports by Management Level and Industry", size(small))

graph export "${output}/graphs/Figure_B6.pdf", replace

}

* Table C1: Gender Gap in Senior Management: Pooled Sample
if `p31'==1{
* VERSION WTIHOUT ADDITIONAL FIRM DATA OTHER THAN LINKEDIN's
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
//keep if Class <=2015


eststo clear
keep if year_since_grad>=1 & year_since_grad<=15
sort linkedin_id year_since_grad


gen exp2 = exp*exp



rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

local pre_char pre_exp pre_any_mgr_v3 pre_mgr2_v3 top20 pre_PL2 
local pre_firm pre_size_LI  
local post_firm exp exp2 size_LI PL2  
local post_gap gap_total_c
local post_ind ind_finance ind_consulting ind_healthcare ind_consumer ind_technology 




eststo H:reg mgr2_v3 female  `pre_char' `pre_firm' `post_gap' `post_firm' `post_ind' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
estadd local pre_firm "Yes", replace
estadd local post_firm "Yes", replace
keep if e(sample)==1 // keep same sample
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace



eststo A:reg mgr2_v3 female i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace

eststo C:reg mgr2_v3 female `pre_char' `pre_firm' i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace

eststo D:reg mgr2_v3 female `pre_char' `pre_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


eststo E:reg mgr2_v3 female `pre_char' `pre_firm' `post_gap' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


eststo F:reg mgr2_v3 female `pre_char' `pre_firm' `post_gap' `post_firm' pre_i_* i.Class##i.year, cluster(linkedin_id)
estadd local classfe "Yes" , replace
estadd local preindustryfe "Yes" , replace
estadd local postgap "Yes" , replace
estadd local pre_char "Yes", replace
estadd local pre_firm "Yes", replace
estadd local post_firm "Yes", replace
sum mgr2_v3 
estadd scalar r(mean), replace
sum mgr2_v3 if female==0
scalar male_mean = r(mean)
estadd scalar male_mean, replace


lab var female "Female"
lab var pre_exp "Pre-MBA Experience"
lab var exp "Post-MBA Experience"
lab var exp2 "Post-MBA Experience Squared"
lab var gap_total_c "Cumulative Months of Career Break"
lab var pre_any_mgr_v3 "Pre-MBA Management Experience" 
lab var pre_mgr2_v3 "Pre-MBA Senior-Level Management Experience"
lab var pre_founder "Pre-MBA Entrepreneur"
lab var pre_i_fin "Worked in Finance"
lab var pre_i_cons "Worked in Consulting"
lab var pre_i_good "Worked in Consumer Goods"
lab var pre_i_hlth "Worked in Healthcare"
lab var pre_i_tech "Worked in Tech"
lab var pre_PL "Pre-MBA P\&L Role"
lab var pre_i_oth "Worked in Other Industries"
lab var pre_big "Worked in Firm with 5,000+ Employees"
lab var pre_medium  "Worked in Firm with 200-4,999 Employees"
lab var pre_small  "Worked in Firm with Less than 200 Employees"
lab var pre_top_100_firm "Worked in Top 100 MBA Firm"
lab var us_locality "U.S. Locality"
lab var top20 "Top-20 Undergrad"
lab var ivy "Ivy League Undergrad"
lab var small "Working in Firm with Less than 200 Employees"
lab var medium "Working in Firm with 200-4,999 Employees"
lab var big "Working in Firm with 5,000+ Employees"
lab var PL "P\&L Role"
lab var pre_PL2 "Worked in P\&L Role"
lab var pre_size_LI "Pre-MBA Firm Size"
//lab var pre_ihs_stars_med "Worked in Female-Friendly Firm"

esttab A C D E F H using "${output}/tables/Table_C1.tex", replace ///
	 keep(female ) se star(* .10 ** .05 *** .01) r2 ///
	 s(classfe pre_char preindustryfe postgap post_firm postindustryfe   mean male_mean r2 N  , ///
	 label("Class x Year FE" "Pre-MBA Characteristics"  ///
	 "Pre-MBA Industry FE" "Cummulative Months of Career Break" "Post-MBA Characteristics" "Post-MBA Industry FE"  ///
	 "Mean" "Mean (Male)" "\(R^2\)" "N" )) ///
	 label interaction(" $\times$ ") nomtitles booktabs f noomitted nobaselevel
}

* Figure E1: Distribution of Residualized Actual and Simulated Female Share
if `p32'==1{
eststo clear
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15

bys linkedin_id: keep if _n==1
	


*TEST FOR RANDOM ASSIGNMENT

local n=999
preserve
bys Class SectionGroupNumber female: keep if _n==1 
keep Class SectionGroupNumber female femaleshare_section
tempfile new_femaleshare
save `new_femaleshare', replace
restore		

set seed 2407

preserve
	gen randomsection = .
	gen i=0
	forval c=2000/2018{ 
		*completely random
		levelsof SectionGroupNumber if Class==`c', local(section_random)
		local number: word count `section_random'
		foreach s of local section_random{
			replace i=i+1/`number' if Class==`c'
			gen random = runiform() if Class==`c'
			replace randomsection = `s' if random <= i & randomsection==. & Class==`c'
			drop random
		}
	}
	
	cap drop SectionGroupNumber
	cap drop section_id
	gen SectionGroupNumber = randomsection
	egen section_id = group(Class SectionGroupNumber)
	merge m:1 Class SectionGroupNumber female using `new_femaleshare', update replace

	di `j'
	
	*do analysis at the section level
	bys Class SectionGroupNumber: keep if _n==1
	foreach y in femaleshare{	
		eststo `y': capture quietly reg `y' i.Class ///
		 , cluster(section_id)
		
		predict femaleshare_residuals, residuals

	keep Class SectionGroupNumber femaleshare_residuals
	gen id="simulated"
	gen id2=1
	save "${data}/analysis/random_distrib_test.dta", replace
		
	}	
	restore

forval j = 1(1)`n'{
	preserve
	gen randomsection = .
	gen i=0
	forval c=2000/2018{ 
		*completely random
		levelsof SectionGroupNumber if Class==`c', local(section_random)
		local number: word count `section_random'
		foreach s of local section_random{
			replace i=i+1/`number' if Class==`c'
			gen random = runiform() if Class==`c'
			replace randomsection = `s' if random <= i & randomsection==. & Class==`c'
			drop random
		}
	}
	
	cap drop SectionGroupNumber
	cap drop section_id
	gen SectionGroupNumber = randomsection
	egen section_id = group(Class SectionGroupNumber)
	merge m:1 Class SectionGroupNumber female using `new_femaleshare', update replace

	di `j'
	
	*do analysis at the section level
	bys Class SectionGroupNumber: keep if _n==1
	foreach y in femaleshare{	
		eststo `y': capture quietly reg `y' i.Class ///
		 , cluster(section_id)
		
		predict femaleshare_residuals, residuals
	keep Class SectionGroupNumber femaleshare_residuals
	gen id="simulated"
	gen id2=1+`j'
	append using "${data}/analysis/random_distrib_test.dta"
	save "${data}/analysis/random_distrib_test.dta", replace
		
	}	
	restore
}



*true coefficient
*do analysis at the section level
bys Class SectionGroupNumber: keep if _n==1
foreach y in femaleshare{	
	eststo `y': capture quietly reg `y' i.Class ///
		 , cluster(section_id)
	predict femaleshare_residuals, residuals
	
	keep Class SectionGroupNumber femaleshare_residuals
	gen id="true"
	gen id2=.
	append using "${data}/analysis/random_distrib_test.dta"
	save "${data}/analysis/random_distrib_test.dta", replace
	
}	
	
use "${data}/analysis/random_distrib_test.dta", clear

twoway (kdensity femaleshare_residuals if id=="simulated", color("162 162 161")) ///
	(kdensity femaleshare_residuals if id=="true", color("25 81 144")), ///
	legend(row(1) size(small) order(1 "Simulated" 2 "Actual" )) ///
       ytitle("Density") xtitle("Residuals") plotregion(fcolor(white)) ///
	graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
	
graph export "${output}/graphs/Figure_E1.eps",replace


}

* Figure F1: Effect of Female Peers on Senior Management: Robustness Checks
if `p33'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15

sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'


*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay


bys linkedin_id: gen years_count = _N
	 
*MATRIX
matrix results_i = J(10,3,.)
matrix coln results_i = b ll95 ul95 
matrix rown results_i = 1 2 3 4 5 6 7 8 9 10
*POOLED REGRESSIONS
foreach x in mgr2_v3 {

*look at preperiod
	eststo clear
	
	local i = 1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
	
	local i=`i'+1
	preserve
		replace mgr2_v3=0 if employed_filled==0
		eststo `x'_filled: reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum `x', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x'_filled, addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
	restore
	
	local i = `i'+1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if Class>=2000 & Class<=2008 & years_count==15, cluster(section_id)
		 
		sum `x' if Class>=2000 & Class<=2008 & years_count==15, d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		
		preserve
		bys section_id: keep if _n==1
		sum femaleshare_section, d
		local p1 = `r(p1)'
		local p99 = `r(p99)'
		restore

			
	local i = `i'+1
	eststo mgr2_v3_cond: reg mgr2_v3_cond femaleshare_male ///
		femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
			
		sum mgr2_v3_cond, d
		local mean = r(mean)
		local sd = r(sd)
		eststo mgr2_v3_nof, addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)

	
		
		local i = `i'+1
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
             pre_mgr2_v3_m##i.female  ///
             c.pre_i_fin##i.female ///
             i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if femaleshare>=`p1' & femaleshare<=`p99', cluster(Class)
		 
		sum `x' if femaleshare>=`p1' & femaleshare<=`p99' & female==1, d
        local mean_f = r(mean)
        sum `x' if femaleshare>=`p1' & femaleshare<=`p99' & female==0, d
        local mean_m = r(mean)
			
		sum `x' if femaleshare>=`p1' & femaleshare<=`p99', d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd')
		estadd local classfe "Yes" , replace
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		
	local i = `i'+1
		eststo mgr2_v3_nof: reg mgr2_v3_nof femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 , cluster(section_id)
		 
		sum mgr2_v3_nof, d
		local mean = r(mean)
		local sd = r(sd)
		eststo mgr2_v3_nof, addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
	

	local i = `i'+1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if i_male!=. , cluster(section_id)
		 
		sum `x' if i_male!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)

	local i = `i'+1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 if ihs_stars!=. , cluster(section_id)
		 
		sum `x' if ihs_stars!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		
		
	local i = `i'+1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 i.i_categorical, cluster(section_id)
		 
		sum `x' if i_categorical!=., d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
		
		local i = `i'+1
	eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 if i_fin!=1, cluster(section_id)
		 
		sum `x' if i_fin!=1, d
		local mean = r(mean)
		local sd = r(sd)
		eststo `x', addscalars(mean `mean' sd `sd')
		lincom femaleshare_female
		cap matrix results_i[`i',1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)

		
		
}
	
	
	
	
	 coefplot ///
	(matrix(results_i[,1]), ci((results_i[,2] results_i[,3])) label("Female Share x Female") ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)), ///
	 coeflabels(1="Main Result" 2="Alternative Nonemployment Definition" ///
	 3="Balanced Sample" 4="Conditional on Working" 5="Without Outliers" 6="With Founders" ///
	 7="Sample with Industry Data" 8="Sample with Female-Friendly Firm Data" ///
	 9="With Industry Fixed Effect" 10="Without Finance") ///
	 ytitle("") xlabel(-1(0.5)1.5) xscale(range(-1(0.5)1.5)) xline(0) ///
	 base omitted legend(position(6)) ///
	 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)  legend(rows(1))
	 graph export "${output}/graphs/Figure_F1.png",replace



}

* Figure F2: Effect of Female Peers on Holding Senior Management Positions Using Placebo Sections
if `p34'==1{
eststo clear
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15
		

sort linkedin_id year_since_grad


*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
local fam_vars ihs_stars_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'


*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay



*RANDOM ASSIGNMENT

	local n=1000

	matrix coeffs = J(`n',4,.)
	matrix coln coeffs = ate ate_true
	matrix rown coeffs = 1:`n'

preserve
bys Class SectionGroupNumber female: keep if _n==1 
keep Class SectionGroupNumber female femaleshare_male femaleshare_female
tempfile new_femaleshare
save `new_femaleshare', replace
restore		

set seed 2407
forval j = 1(1)`n'{
	preserve
	gen randomsection = .
	gen i=0
	forval c=2000/2018{ 
		*completely random
		levelsof SectionGroupNumber if Class==`c', local(section_random)
		local number: word count `section_random'
		foreach s of local section_random{
			replace i=i+1/`number' if Class==`c'
			gen random = runiform() if Class==`c'
			replace randomsection = `s' if random <= i & randomsection==. & Class==`c'
			drop random
		}
	}
	
	cap drop SectionGroupNumber
	cap drop section_id
	gen SectionGroupNumber = randomsection
	egen section_id = group(Class SectionGroupNumber)
	drop _merge
	merge m:1 Class SectionGroupNumber female using `new_femaleshare', update replace

	di `j'
	foreach y in mgr2_v3{	
		eststo `y': capture quietly reg `y' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			     c.m_pre_mgr2_v3 ///
			     c.m_pre_i_fin ///
			     c.m_pre_i_cons ///
			     c.m_pre_i_oth ///
			     c.m_pre_PL2 ///
			     c.m_white ///
			     c.m_foreign ///
			, cluster(section_id)

		if _rc==0{
		est restore `y'
		lincom femaleshare_male
		matrix coeffs[`j',1] = `r(estimate)'
		
		
		est restore `y'
		lincom femaleshare_female
		matrix coeffs[`j',3] = `r(estimate)'
		
			}
		else {
		matrix coeffs[`j',1] = .
		matrix coeffs[`j',3] = .
		}
	}	
	restore
}



*true coefficient

foreach y in mgr2_v3{	
	eststo `y': reg `y' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
			 i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			     c.m_pre_mgr2_v3 ///
			     c.m_pre_i_fin ///
			     c.m_pre_i_cons ///
			     c.m_pre_i_oth ///
			     c.m_pre_PL2 ///
			     c.m_white ///
			     c.m_foreign ///
			, cluster(section_id)


	est restore `y'
	lincom femaleshare_male
	forval j = 1(1)`n'{
		matrix coeffs[`j',2] = `r(estimate)'
	}
	
	
	est restore `y'
	lincom femaleshare_female
	forval j = 1(1)`n'{
		matrix coeffs[`j',4] = `r(estimate)'
	}
}	
	
	
clear
svmat coeffs
save "${data}/analysis/random_coeff.dta", replace
	
use "${data}/analysis/random_coeff.dta", clear

cumul coeffs1 , gen(empiricaldist) equal
sort coeffs1
gen dist_025 = abs(empiricaldist-0.025)
egen min_dist_025 = min(dist_025)
gen dist_975 = abs(empiricaldist-0.975)
egen min_dist_975 = min(dist_975)

gen lower_cit = coeffs1 if dist_025==min_dist_025
egen lower_ci = min(lower_cit)
sum lower_ci
local lci = r(mean)
gen upper_cit = coeffs1 if dist_975==min_dist_975
egen upper_ci = min(upper_cit)
sum upper_ci
local uci = r(mean)

sum coeffs2
local coeff = r(mean)


twoway kdensity coeffs1, xline(`lci') xline(`uci') xline(`coeff')

hist coeffs1, fcolor(none) lcolor(blue) graphregion(fcolor(white)) xtitle("Estimated Effect: Men") ///
ytitle("Density") xline(`coeff') xlabel(-.3(.1).90)
graph export "${output}/graphs/Figure_F2a.eps",replace


cumul coeffs3 , gen(empiricaldist3) equal
sort coeffs3
gen dist_025_3 = abs(empiricaldist3-0.025)
egen min_dist_025_3 = min(dist_025_3)
gen dist_975_3 = abs(empiricaldist3-0.975)
egen min_dist_975_3 = min(dist_975_3)

gen lower_cit_3 = coeffs3 if dist_025_3==min_dist_025_3
egen lower_ci_3 = min(lower_cit_3)
sum lower_ci_3
local lci_3 = r(mean)
gen upper_cit_3 = coeffs3 if dist_975_3==min_dist_975_3
egen upper_ci_3 = min(upper_cit_3)
sum upper_ci_3
local uci_3 = r(mean)

sum coeffs4
local coeff_4 = r(mean)


twoway kdensity coeffs3, xline(`lci_3') xline(`uci_3') xline(`coeff_4')

hist coeffs3, fcolor(none) lcolor(blue) graphregion(fcolor(white)) xtitle("Estimated Effect: Women") ///
ytitle("Density") xline(`coeff_4') xlabel(-.3(.1).90)
graph export "${output}/graphs/Figure_F2b.eps",replace
	

}

* Table F1: Effect of Female Peers on Senior Management: Pre-MBA
if `p35'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 
		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	


eststo clear
matrix results1 = J(3,3,.)
matrix results2 = J(3,3,.)
matrix coln results1 = b ll95 ul95 
matrix rown results1 = 1 2 3 
matrix coln results2 = b ll95 ul95 
matrix rown results2 = 1 2 3 
foreach x in mgr2_v3 {

*look at preperiod
	eststo clear
	forval i =-4/-2{
		local j=`i'+5
		eststo `x'_`j': reg `x' femaleshare_male femaleshare_female i.female  ///
			 i.Class##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
			 if year_since_grad==`i' , cluster(section_id)
		
		sum `x' if year_since_grad==`i' & female==1, d
        local mean_f = r(mean)
        sum `x' if year_since_grad==`i' & female==0, d
        local mean_m = r(mean)
			
		sum `x' if year_since_grad==`i', d
		local mean = r(mean)
		local sd = r(sd)
		test femaleshare_male = femaleshare_female
		local p_value = r(p)
		eststo `x'_`j', addscalars(mean `mean' mean_f `mean_f' mean_m `mean_m' sd `sd' p_value `p_value')
		local var 1.female
		cap matrix results1[`j',1] = _b[`var'], _b[`var'] - 1.96*_se[`var'], _b[`var'] + 1.96*_se[`var']
		local var c.femaleshare_female
		cap matrix results2[`j',1] = _b[`var'], _b[`var'] - 1.96*_se[`var'], _b[`var'] + 1.96*_se[`var']
		
	}
		
	
	esttab `x'_1 `x'_2 `x'_3  using "${output}/tables/Table_F1.tex", replace ///
	 keep(femaleshare_female) se star(* .10 ** .05 *** .01) r2 ///
	 s(mean_f mean_m r2 N, ///
     label("Female Mean" "Male Mean" "\(R^2\)" "N") ///
     fmt(%9.3f %9.3f %9.3f %9.3g)) ///
	 label interaction(" $\times$ ") mtitles("Year -4" "Year -3" "Year -2") booktabs f noomitted nobaselevel

}	
}

* Figure G1: Effect of Female Peers on Senior Management in Female-Friendly Firms by Component
if `p36'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
	
local missings pre_any_mgr_v3 pre_mgr2_v3 pre_founder ///
		pre_i_fin pre_i_cons pre_i_good pre_i_hlth pre_i_tech pre_i_oth ///
		pre_small pre_medium pre_big pre_top_100_firm pre_size_LI ///
		ivy top20 pre_exp ///
		pre_mgr_v3 pre_vp_dir_v3 pre_svp_v3 pre_csuite_v3 ///
		pre_f_IT pre_f_acct pre_f_adm pre_f_cons pre_f_cus ///
		pre_f_fin pre_f_mgmt pre_f_HR pre_f_legal pre_f_mkt ///
		pre_f_opn pre_f_PR pre_f_prod pre_f_RD pre_f_sales pre_f_strat ///
		pre_PL pre_PL2 

		
foreach var of local missings {
		
		*create missing indicator 
		gen `var'_m = (`var'==.)
		
		*replace missing values with zero
		replace `var'=99 if `var'==.
    }
	

	
keep if year_since_grad>=1 & year_since_grad<=15


sort linkedin_id year_since_grad

*generate manager unconditional on working		
gen mgr2_v3_cond = mgr2_v3
replace mgr2_v3_cond = . if (employed==0 | employed==.) & mgr2_v3==0

gen i_male = (i_fin==1 | i_cons==1 | i_tech==1)
replace i_male =. if (i_good==. & i_hlth==. & i_fin==. & i_cons==. & i_tech==. & i_oth==.)

gen i_female = 1- i_male
replace i_female = 0 if i_oth==1

gen i_male_mgr2_v3 = i_male==1 & mgr2_v3==1
replace  i_male_mgr2_v3  = . if i_male==. | mgr2_v3==.
gen i_female_mgr2_v3 = i_female==1 & mgr2_v3==1
replace  i_female_mgr2_v3  = . if i_female==. | mgr2_v3==.

gen i_male_mgr2_v3_c  = i_male_mgr2_v3 
replace i_male_mgr2_v3_c = . if mgr2_v3 !=1

*industries 
gen i_categorical = 1 if i_fin==1
replace i_categorical = 2 if i_cons==1
replace i_categorical = 3 if i_good==1
replace i_categorical = 4 if i_hlth==1
replace i_categorical = 5 if i_tech==1
replace i_categorical = 6 if i_oth==1

lab def i_categorical 1 "Finance" 2 "Consulting" 3 "Cons. Good" 4 "Healthcare" 5 "Technology" 6 "Other"
lab value i_categorical i_categorical

*functions
encode function_broad, gen(f_broad_categorical)
ta function_broad, gen(function_broad)


rename gd_fem_share_senior_manager gd_fem_share_sr_mgr
rename gd_fem_pct_d_totalpay gd_fem_pct_totpay
rename gd_sr_mgr_fem_pct_d_totalpay gd_sr_mgr_fem_pct_totpay

gen comp_gap = - gd_fem_pct_d_basepay
gen sr_comp_gap = - gd_sr_mgr_fem_pct_d_basepay


*generate lee bounds on ihs_stars
gen ihs_stars_l = ihs_stars
replace ihs_stars_l = 1.1 if ihs_stars==.
gen ihs_stars_u = ihs_stars
replace ihs_stars_u = 4.9 if ihs_stars==.

gen ihs_stars_m = (ihs_stars==.)
gen gd_m = (gd_fem_share_emp==. & gd_fem_share_sr_mgr==. & gd_basepay==. & comp_gap==. & sr_comp_gap==.)
gen fgb_rating_m = (fgb_rating==.)

sum ihs_ratings_count
replace ihs_ratings_count = `r(min)' if ihs_ratings_count==. & ihs_stars==.

*************************************
* Manager and Family Friendly Firms *
*************************************
rename gd_fem_pct_d_totalpay gd_fem_d_tot
rename gd_sr_mgr_fem_pct_d_totalpay gd_mgr_fem_d_tot

preserve
bys firm_id_LI: keep if _n==1
foreach var in fgb_rating paid_weeks board_women_pct gd_fem_d_tot gd_mgr_fem_d_tot{
	
	if "`var'"=="paid_weeks" | "`var'"=="board_women_pct"{
	sum `var', d
	}
	if "`var'"=="fgb_rating"{
	sum `var' [aweight=fgb_reviews], d
	}
	if "`var'"=="gd_fem_d_tot" | "`var'"=="gd_mgr_fem_d_tot" {
	sum `var' [aweight=gd_reviews], d
	}
	gen `var'_med = (`var'>=`r(p50)')
	replace `var'_med = . if `var'==.
	replace `var'_med = 0 if employed == 0
	gen `var'_nomed = 1-`var'_med 
}
keep firm_id_LI fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med
tempfile median
save `median', replace 
restore

merge m:1 firm_id_LI using `median'
drop _merge


local fam_vars ihs_stars_med ihs_opportunities_med ihs_flexibility_med ihs_enrichment_med ihs_compensation_med ///
			ihs_family_med ihs_culture_med ///
			fgb_rating_med paid_weeks_med board_women_pct_med ///
			gd_fem_d_tot_med gd_mgr_fem_d_tot_med

foreach var in `fam_vars'{
	gen `var'_mgr = (`var'==1 & mgr2_v3==1)
	replace `var'_mgr=. if `var'==. | mgr2_v3==.
	
	gen `var'_nomgr = (`var'==0 & mgr2_v3==1)
	replace `var'_nomgr=. if `var'==. | mgr2_v3==.
}	

gen ihs_stars_no_med_mgr = (ihs_stars_med==0 & mgr2_v3==1)
replace ihs_stars_no_med_mgr=. if ihs_stars_med==. | mgr2_v3==.


*create manager + external
preserve
drop if year_since_grad==1

collapse (max)external, by(linkedin_id firmnum mgr2_v3)
drop if firmnum==.
gen external_mgr_t = (external==1 & mgr2_v3==1)
replace external_mgr_t=. if external==. | mgr2_v3==.
gen internal_mgr = (mgr2_v3==1 & external_mgr==0)
replace internal_mgr=. if mgr2_v3==. | external_mgr==.
tempfile ext_int
save `ext_int', replace 
restore

merge m:1 linkedin_id firmnum mgr2_v3 using `ext_int'
drop _merge 

*create total number of years in senior manager positions
bys linkedin_id: egen mgr2_v3_tot_years = total(mgr2_v3)

*rename variables with too long names
rename gd_sr_mgr_fem_pct_d_basepay gd_sr_mgr_fem_pct_d_base

gen gd_i_bonuspay = gd_i_totalpay - gd_i_basepay


preserve	 
*COEFPLOT WITH INDICES
bys firm_id_LI: keep if _n==1



foreach x in size_LI ///
			gd_totalpay gd_totalpaysenior_manager ///
			gd_fem_pct_totpay gd_sr_mgr_fem_pct_totpay ///
			fgb_rating paid_weeks board_women_pct{
			
			egen z_`x' = std(`x')
}

gen weights = ihs_ratings_count + fgb_reviews

keep firm_id_LI z_size_LI top_100_firm ///
			z_gd_totalpay z_gd_totalpaysenior_manager ///
			z_gd_fem_pct_totpay z_gd_sr_mgr_fem_pct_totpay ///
			ihs_stars ihs_opportunities ihs_flexibility ihs_enrichment ihs_compensation ///
			ihs_family ihs_culture  ///
			z_fgb_rating z_paid_weeks z_board_women_pct weights

tempfile firm_ihs
save `firm_ihs', replace 

restore

merge m:1 firm_id_LI using `firm_ihs'
drop _merge

rename z_gd_totalpaysenior_manager z_gd_totalpaysr_manager
rename z_gd_sr_mgr_fem_pct_totpay z_gd_sr_mgr_fem_pct_tot


local j=1
foreach x in ihs_stars_med_mgr ihs_stars_med_nomgr ihs_opportunities_med_mgr ihs_opportunities_med_nomgr ///
	ihs_flexibility_med_mgr ihs_flexibility_med_nomgr ihs_enrichment_med_mgr ihs_enrichment_med_nomgr ///
	ihs_compensation_med_mgr ihs_compensation_med_nomgr ihs_family_med_mgr ihs_family_med_nomgr ///
	ihs_culture_med_mgr ihs_culture_med_nomgr ///
			{
		*MATRIX
		matrix results_`j' = J(1,3,.)
		matrix coln results_`j' = b ll95 ul95 
		matrix rown results_`j' = 1
		
		*POOLED REGRESSIONS
		eststo `x': reg `x' femaleshare_male femaleshare_female i.female ///
		 i.Class##i.year_since_grad##i.female ///
             i.top20##i.female ///
			 i.top20_m##i.female ///
			 pre_mgr2_v3##i.female  ///
			 pre_mgr2_v3_m##i.female  ///
			 c.pre_i_fin##i.female ///
			 i.pre_i_fin_m##i.female ///
			 c.m_pre_any_mgr_v3 ///
			 c.m_pre_mgr2_v3 ///
			 c.m_pre_i_fin ///
			 c.m_pre_i_cons ///
			 c.m_pre_i_oth ///
			 c.m_pre_PL2 ///
			 c.m_white ///
			 c.m_foreign ///
		 [aweight=ihs_ratings_count], cluster(section_id)
		 
			sum `x', d
			local mean = r(mean)
			local sd = r(sd)
			eststo `x', addscalars(mean `mean' sd `sd')
			estadd local classfe "Yes" , replace
			estadd local ind_fe "Yes" , replace
			
			lincom femaleshare_female
			cap matrix results_`j'[1,1] = r(estimate), r(estimate) -1.96*r(se), r(estimate) + 1.96*r(se)
				
		local j = `j'+1
		
}

 
	 
	 coefplot ///
	(matrix(results_1[,1]), ci((results_1[,2] results_1[,3])) rename(1="Female-Friendly Firm") offset(0) label(Above Median) ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_2[,1]), ci((results_2[,2] results_2[,3])) rename(1="Female-Friendly Firm") offset(-0.3) label(Below Median) ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_3[,1]), ci((results_3[,2] results_3[,3])) rename(1="Gender Equal Opportunities") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_4[,1]), ci((results_4[,2] results_4[,3])) rename(1="Gender Equal Opportunities") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_5[,1]), ci((results_5[,2] results_5[,3])) rename(1="Work Schedule Flexibility") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_6[,1]), ci((results_6[,2] results_6[,3])) rename(1="Work Schedule Flexibility") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_7[,1]), ci((results_7[,2] results_7[,3])) rename(1="Professional Enrichment") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_8[,1]), ci((results_8[,2] results_8[,3])) rename(1="Professional Enrichment") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_9[,1]), ci((results_9[,2] results_9[,3])) rename(1="Fair Compensation") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_10[,1]), ci((results_10[,2] results_10[,3])) rename(1="Fair Compensation") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_11[,1]), ci((results_11[,2] results_11[,3])) rename(1="Family Friendliness") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_12[,1]), ci((results_12[,2] results_12[,3])) rename(1="Family Friendliness") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)) ///
	 (matrix(results_13[,1]), ci((results_13[,2] results_13[,3])) rename(1="Workplace Culture") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) ///
	(matrix(results_14[,1]), ci((results_14[,2] results_14[,3])) rename(1="Workplace Culture") offset(-0.3) nokey ///
	 mcolor(navy*.50) ciopts(color(navy*.50)) mlabsize(medium)), ///
	 ytitle("") xlabel(-2(1)3) xscale(range(-2(1)3)) xline(0) ///
	 base omitted ///
	 note("Observations = `e(N)'") ///
	 plotregion(fcolor(white)) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)  legend(rows(1))
	 graph export "${output}/graphs/Figure_G1.png",replace
}

* Table H1: Survey Response Balance
if `p37'==1{
use "${data}/raw/LI_workhistory_yearly_educ_US_gender_fake.dta",clear
bys linkedin_id: egen ever_ever_mgr2_v3 = max(ever_mgr2_v3)

sort linkedin_id, stable
by linkedin_id: keep if _n==1

merge 1:1 linkedin_id using "${data}/raw/survey/MBA_survey_matched_fake.dta" , gen(match_linkedin)  
drop matched
gen matched = match_linkedin==3

tab matched female
br if matched==1 & female==0


keep if female==1

lab var femaleshare_section "Share of Female Section Peers"
lab var pre_exp "Pre-MBA Years of Experience"
lab var pre_any_mgr_v3 "Any Pre-MBA Management Experience" 
lab var pre_mgr2_v3 "Any Pre-MBA Senior-Level Management Experience"
lab var ever_ever_mgr2_v3 "Ever Post-MBA Senior-Level Management Experience "
lab var pre_i_fin "\quad Finance"
lab var pre_i_cons "\quad Consulting"
lab var pre_i_good "\quad Consumer Goods"
lab var pre_i_hlth "\quad  Healthcare"
lab var pre_i_tech "\quad  Tech"
lab var pre_i_oth "\quad  Other Industries"
lab var pre_big "\quad  5,000+ Employees"
lab var pre_medium  "\quad 200-4,999 Employees"
lab var pre_small  "\quad  Less than 200 Employees"
lab var pre_top_100_firm "Worked in Top 100 MBA Firm"
lab var pre_PL "Worked in P\&L Role"
lab var us_locality "U.S. Locality"
lab var top20 "Top-20 Undergrad"
lab var ivy "Ivy League Undergrad"


local variables femaleshare_section pre_exp pre_any_mgr_v3 pre_mgr2_v3 ever_ever_mgr2_v3 top20 Class //white black asian minority
eststo clear
estpost sum `variables'
est store A

estpost sum `variables' if matched==0
est store B

estpost sum `variables' if matched==1
est store C

estpost ttest `variables', by(matched) 
est store D
estadd matrix mean = e(b)
estadd matrix sd = e(p)

esttab A B C D using "${output}/tables/Table_H1.tex", replace cells(mean(fmt(2) star) sd(par))  star(* .10 ** .05 *** .01)  ///
 label nonum collabels(none) booktabs f wide mtitles("All" "Non-Respondents" "Respondents" "Difference") 
}

* Figure H1: Composition of 10 Closest Professional Contacts
if `p38'==1{
use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"

/*
-descriptive graph over time since graduation of "Among your 10 closest professional contacts, how many are: women, People from your MBA class, People from your MBA section"
*/

preserve
collapse contacts_*,by(Class)
gen years = 2023-Class
keep if years <=20
twoway connected contacts_female years || connected contacts_MBA years || connected contacts_MBA_s years, ///
	legend(order(1 "Women" 2 "People from MBA Class" 3 "People from MBA Section")) xtitle("Years Since MBA") graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
graph export "${output}/graphs/Figure_H1.png", replace

restore
}

* Table H2: Effect of Female Peers on Peer Composition
if `p39'==1{
use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"

/*
-effect of female peers on "Thinking of your 10 closest MBA contacts, how many of them are women?"

-effect of female peers on "How many of these women are from your same section?"
*/
gen mba_contacts_women_p = mba_contacts_women/10
gen mba_contacts_women_s_p = mba_contacts_women_s/10 
gen mba_contacts_women_s_p_c = mba_contacts_women_s/mba_contacts_women 
lab var mba_contacts_women_p "Female Share of 10 Closest MBA Contacts"
lab var mba_contacts_women_s_p "Female Section Peer Share of 10 Closest MBA Contacts"
lab var mba_contacts_women_s_p_c "Female Section Peer Share of Closest Female MBA Contacts"


gen contacts_female_share = contacts_female/10
gen contacts_MBA_share =contacts_MBA/10



gen any_reunion = reunions_1 ==1 | reunions_2==1 | reunions_3==1 | reunions_4==1 | reunions_5==1
replace any_reunion = . if reunions_1 ==. & reunions_2==. & reunions_3==. & reunions_4==. & reunions_5==.

gen total_reunion = 0
forval i = 1/5{
	replace total_reunion = total_reunion + 1 if reunions_`i' ==1
} 
replace total_reunion = . if reunions_1 ==. & reunions_2==. & reunions_3==. & reunions_4==. & reunions_5==.



local n = 1
cap drop p_value
gen p_value = . 
foreach y in mba_contacts_women_p mba_contacts_women_s_p mba_contacts_women_s_p_c contacts_female_share contacts_MBA_share contacts_MBA_s any_reunion total_reunion{
	eststo `y': areg `y' femaleshare,ab(Class)  cluster(section_id)
	replace p_value = (2 * ttail(e(df_r), abs(_b[femaleshare] / _se[femaleshare]) ) ) if _n==`n'
	
	est restore `y'
	estadd local classfe "Yes" , replace
	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
	
	local n = `n' + 1
	
}
qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in mba_contacts_women_p mba_contacts_women_s_p mba_contacts_women_s_p_c contacts_female_share contacts_MBA_share contacts_MBA_s any_reunion total_reunion{
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}
esttab mba_contacts_women_p mba_contacts_women_s_p mba_contacts_women_s_p_c contacts_female_share contacts_MBA_share contacts_MBA_s any_reunion total_reunion using  "${output}/tables/Table_H2.tex", replace ///
 keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
 s(classfe mean sd qvalue r2 N, ///
 label("Class FE" "Mean" "SD" "\(q\)-value"  "\(R^2\)" "N")) ///
 label interaction(" $\times$ ") mtitles("\shortstack{Female \\ Share \\ Among 10 \\ Closest \\ MBA Contacts}" ///
 "\shortstack{Female \\ Section \\ Peer \\ Share \\ Among 10 \\ Closest \\ MBA Contacts}" ///
 "\shortstack{Female \\ Section \\ Peer \\ Share \\ Among \\ Closest \\ Female \\ MBA Contacts}" "\shortstack{Female \\ Share}" ///
 "\shortstack{MBA \\ Peer \\ Share}" ///
 "\shortstack{MBA \\ Section \\ Peer Share}" "\shortstack{Any Reunion \\ Attended}" ///
 "\shortstack{Number of \\ Reunions \\ Attended}") booktabs f noomitted nobaselevel
	
}

* Table H3: Comparison of IHS Ratings and Female-Friendliness Measures from Survey Responses
if `p40'==1{



use "${data}/raw/survey/survey_ihs_fake.dta", clear
merge 1:m employer_name_id using "${data}/raw/survey/MBA_survey.dta"
keep if _merge==3




* Graphical correlations (and reg) for Female Friendly Validation
// -to validate our measure of FFF
// 1.Approximately what percentage of C-level executive positions and board members in your firm are women?
// current_female_board
//
// 2.Thinking about your current job (or if not employed, your last job), how female-friendly would you rate your employer (on a scale of 1 to 5, where 1 is not at all and 5 is extremely female-friendly)?
// female_friendly
//
// 3.How often do the demands of your job interfere with your family life?
// demands_family_life

replace female_friendly = . if female_friendly==6 

/* Put in Regression Table All Together */


eststo clear 

local n = 1
cap drop p_value 
gen p_value = . 
foreach y in current_female_board demands_family_life female_friendly{
	eststo `y': areg `y' ihs_stars,ab(Class) cluster(section_id)
	
	
	replace p_value = (2 * ttail(e(df_r), abs(_b[ihs_stars] / _se[ihs_stars]) ) ) if _n==`n'
	est restore `y'
	estadd local classfe "Yes" , replace
	estadd local yearfe "No" , replace
	sum `y' 
	estadd scalar r(mean), replace
	local n = `n' + 1
}


qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in current_female_board demands_family_life female_friendly{
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}


lab var ihs_stars "IHS Rating"
esttab current_female_board demands_family_life female_friendly using "${output}/tables/Table_H3.tex", replace ///
	 keep(ihs_stars) se star(* .10 ** .05 *** .01) r2 ///
	 s(classfe mean r2 qvalue N  , ///
	 label("Class FE"  ///
	 "Mean" "\(q\)-value" "\(R^2\)" "N" )) ///
	 label mtitles("\shortstack{Female \% of \\ C-level positions}" "\shortstack{Demands of job \\ interfere with \\ your family life}" "\shortstack{Level of \\ female-friendliness}") booktabs f noomitted nobaselevel

}

* Figure H2: Work and Career Choices Due to Children
if `p41'==1{
use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"

 
//effect of children

forval i = 1/12{
	gen children_effect_dummy_`i' = children_effect_`i'==1
	replace children_effect_dummy_`i' = . if children_effect_`i'==.
	
	gen children_effect_work_dummy_`i' = children_effect_work_`i'==1
	replace children_effect_work_dummy_`i' = . if children_effect_work_`i'==.
	
}
 

preserve
collapse children_effect_dummy_* 
gen x = 1
reshape long children_effect_dummy_  ,i(x) j(type)
gen type_label = "Leave your job" if type==1
replace type_label = "Find a job with fewer hours" if type==2
replace type_label = "Reduce your work hours" if type==3
replace type_label = "Work part time" if type==4
replace type_label = "Leave the paid workforce" if type==5
replace type_label = "Change sectors" if type==6
replace type_label = "Encourage partner to cut down on their work hours" if type==7
replace type_label = "Move closer to family" if type==8
replace type_label = "Lobby to change workplace policies" if type ==9
replace type_label = "Work more hours"  if type==10
replace type_label = "Spend more time working from home" if type ==11
replace type_label = "Other" if type ==12


graph hbar (mean) children_effect_dummy_, over(type_label, sort(1)  descending label(labsize(small)))  ytitle("% Yes") graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
graph export "${output}/graphs/Figure_H2.png", replace
restore 
}

* Figure H3: Adverse Effects at Work Due to Children
if `p42'==1{
use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"

 
//effect of children

forval i = 1/12{
	gen children_effect_dummy_`i' = children_effect_`i'==1
	replace children_effect_dummy_`i' = . if children_effect_`i'==.
	
	gen children_effect_work_dummy_`i' = children_effect_work_`i'==1
	replace children_effect_work_dummy_`i' = . if children_effect_work_`i'==.
	
}
 



preserve
collapse children_effect_work_dummy_* 
gen x = 1
reshape long children_effect_work_dummy_  ,i(x) j(type)
gen type_label = "Delay in promotion" if type==1
replace type_label = "Loss of seniority" if type==2
replace type_label = "Questioning of commitment to work" if type==3
replace type_label = "Loss of office space" if type==4
replace type_label = "Pressure to work while on parental leave" if type==5
replace type_label = "Difficulty in obtaining flexible hours or part time work" if type==6
replace type_label = "Loss of clients" if type==7
replace type_label = "Unreasonable work load following parental leave" if type==8
replace type_label = "Loss of challenging assignments" if type ==9
replace type_label = "Loss of opportunities to travel"  if type==10
replace type_label = "Loss of income" if type ==11
replace type_label = "Other" if type ==12


graph hbar (mean) children_effect_work_dummy_, over(type_label, sort(1)  descending label(labsize(small)))  ytitle("% Yes") graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
graph export "${output}/graphs/Figure_H3.png", replace
restore 
}

* Figure H4: Effects of Female Peers on the Work Impacts of Children
if `p43'==1{

use "${data}/raw/survey/MBA_survey.dta", clear
lab var femaleshare "Female share"
 
//effect of children


forval i = 1/12{
	gen children_effect_dummy_`i' = children_effect_`i'==1
	replace children_effect_dummy_`i' = . if children_effect_`i'==.
	
	gen children_effect_work_dummy_`i' = children_effect_work_`i'==1
	replace children_effect_work_dummy_`i' = . if children_effect_work_`i'==.
	
}
 

egen any_children_effect = rowmax(children_effect_dummy_*)
egen any_children_effect_work = rowmax(children_effect_work_dummy_*)
 

// children_effect_dummy_
matrix results = J(12,3,.)
matrix coln results = b ll95 ul95 
forval i = 1/12{
	areg children_effect_dummy_`i' femaleshare, ab(Class) cluster(section_id)
	matrix results[`i',1] = _b[femaleshare], _b[femaleshare] -1.96*_se[femaleshare], _b[femaleshare] +1.96*_se[femaleshare]
}

	
coefplot ///
	(matrix(results[,1]), ci((results[,2] results[,3])) rename(r1="Leave your job" r2 = "Find a job with fewer hours" r3 = "Reduce your work hours" r4 = "Work part time" r5 = "Leave the paid workforce" r6 = "Change sectors" r7 = "Encourage partner to cut down on their work hours" r8 = "Move closer to family" r9 = "Lobby to change workplace policies" r10 = "Work more hours"  r11 = "Spend more time working from home" r12 = "Other") offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) , ///
	 ytitle("") xline(0) ylabel(,labsize(small)) ///
	 base omitted  ///
	 graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) legend(rows(1))
	 graph export "${output}/graphs/Figure_H4a.png", replace
	
	
// children_effect_work_dummy_
matrix results = J(12,3,.)
matrix coln results = b ll95 ul95 
forval i = 1/12{
	areg children_effect_work_dummy_`i' femaleshare, ab(Class) cluster(section_id)
	matrix results[`i',1] = _b[femaleshare], _b[femaleshare] -1.96*_se[femaleshare], _b[femaleshare] +1.96*_se[femaleshare]
}

	
coefplot ///
	(matrix(results[,1]), ci((results[,2] results[,3])) rename(r1="Delay in promotion" r2 = "Loss of seniority" r3 = "Questioning of commitment to work" r4 = "Loss of office space" r5 = "Pressure to work while on parental leave" r6 = "Difficulty in obtaining flexible hours or part time work" r7 = "Loss of clients" r8 = "Unreasonable work load following parental leave" r9 = "Loss of challenging assignments" r10 = "Loss of opportunities to travel"  r11 = "Loss of income" r12 = "Other" ) offset(0) nokey ///
	 mcolor(navy) ciopts(color(navy)) mlabsize(medium)) , ///
	 ytitle("") xline(0) ylabel(,labsize(small)) ///
	 base omitted  ///
	 graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) legend(rows(1))
	 graph export "${output}/graphs/Figure_H4b.png", replace
}

* Table H4: Effect of Female Peers on Ambition and Self-Confidence
if `p44'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"

*excuding women who are already extecutives
gen high_ambition = (ambition==1)
replace high_ambition = . if ambition==. | ambition==4 | ambition==3

*including women who are already extecutives among the ambitious
gen high_ambition_v2 = (ambition==1 | ambition==3)
replace high_ambition_v2 = . if ambition==. | ambition==4
gen high_ambition_5yr = (ambition_5yr==1 | ambition_5yr==2 )

replace high_ambition_5yr = . if ambition_5yr==. | ambition_5yr==4 | ambition_5yr==7

gen high_ambition_10yr = (ambition_10yr==1 | ambition_10yr==2)
replace high_ambition_10yr = . if ambition_10yr==. | ambition_10yr==4 | ambition_10yr==7
/*
-effect of female peers on negotiation:
1.Have you negotiated for a raise at this firm?
2.Were you successful in obtaining a raise through negotiation?
3.Have you negotiated for a promotion at this firm?
4.Were you successful in obtaining a promotion through negotiation?
*/

foreach var in negotiate_raise negotiate_raise_suc negotiate_promo negotiate_promo_suc {
	replace `var' = 0 if `var'==2
	replace `var' = . if `var'==4
}

replace satisfied_career = . if satisfied_career==6

			

local n = 1
cap drop p_value
gen p_value = . 
*regressions
foreach y in high_ambition_v2 high_ambition_5yr high_ambition_10yr {
					
	eststo `y': areg `y' femaleshare,ab(Class) cluster(section_id)
	
	replace p_value = (2 * ttail(e(df_r), abs(_b[femaleshare] / _se[femaleshare]) ) ) if _n==`n'
	estadd local classfe "Yes" , replace

	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
	local n = `n' + 1
}


cap drop qvalue rank
qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in high_ambition_v2 high_ambition_5yr high_ambition_10yr {
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}
esttab high_ambition_v2 high_ambition_5yr high_ambition_10yr using ///
				"${output}/tables/Table_H4.tex", replace ///
				keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
				s(classfe mean sd qvalue r2 N, ///
				label("Class FE" "Mean" "SD" "\(q\)-value" "\(R^2\)" "N")) ///
				label interaction(" $\times$ ") mtitles("\shortstack{Would Like to Be \\ or Already Top Executive}" ///
				"\shortstack{See Myself \\ as SVP/C-Level \\ in 5 years}" "\shortstack{See Myself \\ as SVP/C-Level \\ in 10 years}") booktabs f noomitted nobaselevel
 
}

* Table H5: Effect of Female Peers on Negotiation
if `p45'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"

*excuding women who are already extecutives
gen high_ambition = (ambition==1)
replace high_ambition = . if ambition==. | ambition==4 | ambition==3

*including women who are already extecutives among the ambitious
gen high_ambition_v2 = (ambition==1 | ambition==3)
replace high_ambition_v2 = . if ambition==. | ambition==4
gen high_ambition_5yr = (ambition_5yr==1 | ambition_5yr==2 )

replace high_ambition_5yr = . if ambition_5yr==. | ambition_5yr==4 | ambition_5yr==7

gen high_ambition_10yr = (ambition_10yr==1 | ambition_10yr==2)
replace high_ambition_10yr = . if ambition_10yr==. | ambition_10yr==4 | ambition_10yr==7
/*
-effect of female peers on negotiation:
1.Have you negotiated for a raise at this firm?
2.Were you successful in obtaining a raise through negotiation?
3.Have you negotiated for a promotion at this firm?
4.Were you successful in obtaining a promotion through negotiation?
*/

foreach var in negotiate_raise negotiate_raise_suc negotiate_promo negotiate_promo_suc {
	replace `var' = 0 if `var'==2
	replace `var' = . if `var'==4
}

replace satisfied_career = . if satisfied_career==6

local n = 1
cap drop p_value
gen p_value = . 
*regressions
foreach y in negotiate_raise negotiate_raise_suc negotiate_promo negotiate_promo_suc{
					
	eststo `y': areg `y' femaleshare,ab(Class) cluster(section_id)
	replace p_value = (2 * ttail(e(df_r), abs(_b[femaleshare] / _se[femaleshare]) ) ) if _n==`n'

	estadd local classfe "Yes" , replace

	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
	
	local n = `n' + 1
}
cap drop qvalue
qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in negotiate_raise negotiate_raise_suc negotiate_promo negotiate_promo_suc{
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}
esttab negotiate_raise negotiate_raise_suc negotiate_promo negotiate_promo_suc using ///
				"${output}/tables/Table_H5.tex", replace ///
				keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
				s(classfe mean sd qvalue r2 N, ///
				label("Class FE" "Mean" "SD" "\(q\)-value" "\(R^2\)" "N")) ///
				label interaction(" $\times$ ") mtitles("Negotiated Raise" ///
				"\shortstack{Successful \\ Negotiated Raise}" ///
				"Negotiated Promotion" ///
				"\shortstack{Successful \\ Negotiated Promotion}") booktabs f noomitted nobaselevel
				
				


}

* Table H6: Effect of Female Peers on Nonemployment and Career Breaks
if `p46'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"

gen unempl = (emp_status==5)
replace unempl=. if emp_status==.

gen any_leave = any_leave_period==1
replace any_leave = . if any_leave_period==. 




egen total_ml = rowtotal(paid_ml_taken_kid* unpaid_ml_taken_kid*) // if all missing var=0

gen year_since_graduation = 2023-Class
gen years_since_graduation_grp = 1 if year_since_graduation>= 5 & year_since_graduation<=7
replace years_since_graduation_grp = 2 if year_since_graduation>= 8 & year_since_graduation<=10
replace years_since_graduation_grp = 3 if year_since_graduation>= 11 & year_since_graduation<=13
replace years_since_graduation_grp = 4 if year_since_graduation>= 14 & year_since_graduation<=16
replace years_since_graduation_grp = 5 if year_since_graduation>= 17 & year_since_graduation<=19
replace years_since_graduation_grp = 6 if year_since_graduation>= 20 & year_since_graduation<=23

levelsof max_kids, local(max_kids)

*create panel exploiting year of childbirth
forval j=1/`max_kids'{
	egen total_ml_taken_kid`j' = rowtotal(paid_ml_taken_kid`j' unpaid_ml_taken_kid`j') // if all missing var=0
}

reshape long care_resp_kid care_partner_kid care_fam_kid care_daycare_kid care_homecare_kid age_kid paid_ml_avail_kid paid_ml_taken_kid unpaid_ml_taken_kid paid_ml_avail_partner_kid paid_ml_taken_partner_kid unpaid_ml_taken_partner_kid total_ml_taken_kid, i(responseid) j(kid)

replace age_kid = round(age_kid)
gen year_birth_kid = 2023-age_kid
gen year_birth_kid_since_grad = year_birth_kid-Class
drop if year_birth_kid_since_grad==.
gen cum_total_ml_taken = total_ml_taken_kid
sort responseid year_birth_kid_since_grad
replace cum_total_ml_taken = total_ml_taken_kid[_n]+total_ml_taken_kid[_n-1] if responseid[_n-1]==responseid[_n]

keep responseid year_birth_kid_since_grad cum_total_ml_taken unempl max_kids any_leave Class femaleshare section_id
fillin responseid year_birth_kid_since_grad

rename cum_total_ml_taken cum_total_ml_taken_t
sort responseid, stable 
by responseid: egen cum_total_ml_taken = total(cum_total_ml_taken_t)
replace cum_total_ml_taken = . if max_kids==0
rename year_birth_kid_since_grad year_since_graduation

gen years_since_graduation_grp = 1 if year_since_graduation>= 5 & year_since_graduation<=7
replace years_since_graduation_grp = 2 if year_since_graduation>= 8 & year_since_graduation<=10
replace years_since_graduation_grp = 3 if year_since_graduation>= 11 & year_since_graduation<=13
replace years_since_graduation_grp = 4 if year_since_graduation>= 14 & year_since_graduation<=16
replace years_since_graduation_grp = 5 if year_since_graduation>= 17 & year_since_graduation<=19
replace years_since_graduation_grp = 6 if year_since_graduation>= 20 & year_since_graduation<=23

keep if _fillin==0
sort responseid, stable 
by responseid: keep if _n==_N

*regressions

local n = 1
cap drop p_value
gen p_value = . 
*regressions
foreach y in  unempl any_leave cum_total_ml_taken  {
	eststo `y': areg `y' femaleshare,ab(Class) cluster(section_id)
	replace p_value = (2 * ttail(e(df_r), abs(_b[femaleshare] / _se[femaleshare]) ) ) if _n==`n'

	estadd local classfe "Yes" , replace

	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
	local n = `n' + 1
}


cap drop qvalue rank
qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in  unempl any_leave cum_total_ml_taken  {
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}
esttab unempl cum_total_ml_taken any_leave using  "${output}/tables/Table_H6.tex", replace ///
 keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
 s(classfe mean sd qvalue r2 N, ///
 label("Class FE" "Mean" "SD" "\(q\)-value" "\(R^2\)" "N")) ///
 label interaction(" $\times$ ") mtitles("Nonemployed" ///
 "\shortstack{Cumulative \\ Materity Leave \\ (Weeks)}" ///
 "\shortstack{Any Leave \\ (Not Including \\ Family Leave)}") booktabs f noomitted nobaselevel
 


}

* Figure H5: Probability of Having Children
if `p47'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"
/*
-descriptive graph with unemployment rate over time since graduation by gender
*/
gen unempl = (emp_status==5)
replace unempl=. if emp_status==.

/*
-decriptive graphs with months of career breaks (= 3 or more consecutive months of non-employment) over time since graduation by gender
*/

egen total_ml = rowtotal(paid_ml_taken_kid* unpaid_ml_taken_kid*) // if all missing var=0

gen year_since_graduation = 2023-Class
gen years_since_graduation_grp = 1 if year_since_graduation>= 5 & year_since_graduation<=7
replace years_since_graduation_grp = 2 if year_since_graduation>= 8 & year_since_graduation<=10
replace years_since_graduation_grp = 3 if year_since_graduation>= 11 & year_since_graduation<=13
replace years_since_graduation_grp = 4 if year_since_graduation>= 14 & year_since_graduation<=16
replace years_since_graduation_grp = 5 if year_since_graduation>= 17 & year_since_graduation<=19
replace years_since_graduation_grp = 6 if year_since_graduation>= 20 & year_since_graduation<=23

*make graphs

*Family outcomes

destring age_kid1,replace
gen year_first_child = 2023 - age_kid1

forval i = 0/15{
gen has_first_kid_`i' = (Class + `i' - year_first_child >= 0 )
replace has_first_kid_`i' = . if year_first_child==.
replace has_first_kid_`i' = 0 if children ==0
}
preserve
collapse has_first_kid_*
gen i = 1
reshape long has_first_kid_, i(i) j(year_since_grad)
twoway connected has_first_kid  year_since_grad, xtitle("Year Since Graduation") xlabel(0(1)15) ytitle("Probability of Having Any Children") ///
	graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white) graphregion(fcolor(white) ifcolor(white) color(white) icolor(white)) bgcolor(white)
graph export "${output}/graphs/Figure_H5.png", replace

restore
}

* Table H7: Effect of Female Peers on Marriage and Fertility
if `p48'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"

*Family outcomes


gen married = 0 if marital_status == 1
replace married = 1 if marital_status == 2 | marital_status==4 | marital_status==100
replace married = . if marital_status==99

gen partner_mba_dummy = partner_mba==1
replace  partner_mba_dummy = . if mi(partner_mba)

gen any_children = children >0
replace any_children = . if mi(children)

 

local n = 1
cap drop p_value
gen p_value = . 
foreach y in married partner_mba_dummy any_children children{
					
	eststo `y': areg `y' femaleshare,ab(Class) cluster(section_id)
	replace p_value = (2 * ttail(e(df_r), abs(_b[femaleshare] / _se[femaleshare]) ) ) if _n==`n'
	estadd local classfe "Yes" , replace
	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
	local n = `n' + 1
}


cap drop qvalue rank
qqvalue p_value, method(simes) rank(rank) qvalue(qvalue)
local n = 1
foreach y in married partner_mba_dummy any_children children{
	levelsof qvalue if _n==`n',local(q)
	est restore `y'
	estadd scalar qvalue `q', replace
	
	local n = `n' + 1
}
esttab married partner_mba_dummy any_children children using ///
				"${output}/tables/Table_H7.tex", replace ///
				keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
				s(classfe mean sd qvalue r2 N, ///
				label("Class FE" "Mean" "SD" "\(q\)-value" "\(R^2\)" "N")) ///
				label interaction(" $\times$ ") mtitles("\shortstack{Married}" /// 
				"\shortstack{Met Partner \\ from MBA}" ///
				"\shortstack{Any \\ Children}" ///
				"\shortstack{Number of \\ Children}") booktabs f noomitted nobaselevel



}

* Table H8: Effect of Female Peers on Career Satisfaction
if `p49'==1{
use "${data}/raw/survey/MBA_survey.dta", clear

lab var femaleshare "Female share"

/*
-effect of female peers on "How satisfied are you with each of the following aspects of your current position (on a scale of 1 to 5, where 1 is not at all and 5 is extremely satisfied)?"

-effect of female peers on "How satisfied are you with your career (on a scale of 1 to 5, where 1 is not at all and 5 is extremely satisfied)?"

-effect of female peers on "If the decision were up to you, approximately how much longer would you like to stay with your current firm?"
*/

rename satisfied_position_1 satisfied_careergrowth
rename satisfied_position_2 satisfied_compensation
rename satisfied_position_3 satisfied_jobsecurity
rename satisfied_position_4 satisfied_worklifebalance
rename satisfied_position_5 satisfied_recognition
rename satisfied_position_6 satisfied_culturevalues

foreach var in satisfied_careergrowth satisfied_compensation satisfied_jobsecurity satisfied_worklifebalance satisfied_recognition satisfied_culturevalues satisfied_career{
	
	*extremely (e_) satisfied is defined as approximately top tercile
	gen e_`var' = (`var'==5)
	replace e_`var' =. if `var'==. | `var'==6
	
	*very (v_) satisfied is defined as equal or above median
	gen v_`var' = (`var'==5 | `var'==4)
	replace v_`var' =. if `var'==. | `var'==6
}

replace stay_employer=. if stay_employer==3 //prefer not to answer

*extremely (e_) satisfied with employer defined as approximately top tercile (wants to stay for more than 5 years)
gen e_satisfied_employer = (stay_employer==7)
replace e_satisfied_employer =. if stay_employer==. | stay_employer==3
	
*very (v_) satisfied with employer defined as equal or above the median (wants to stay for more than 3 years)
gen v_satisfied_employer = (stay_employer==7 | stay_employer==6)
replace v_satisfied_employer =. if stay_employer==. | stay_employer==3

gen satisfied_employer = 0 if stay_employer==1
replace satisfied_employer = 0.5 if stay_employer==4
replace satisfied_employer = 1.5 if stay_employer==5
replace satisfied_employer = 4 if stay_employer==6
replace satisfied_employer = 5 if stay_employer==7



gen femaleshare_abovemed = (femaleshare> 0.34)
replace femaleshare_abovemed=. if femaleshare==.
replace satisfied_career = . if satisfied_career==6

*regressions
foreach y in satisfied_career {
					
	eststo `y': areg `y' femaleshare,ab(Class) cluster(section_id)
	estadd local classfe "Yes" , replace

	sum `y'
	local mean = r(mean)
	local sd = r(sd)
	eststo `y', addscalars(mean `mean' sd `sd' )
}

				
esttab satisfied_career using ///
				"${output}/tables/Table_H8.tex", replace ///
				keep(femaleshare) se star(* .10 ** .05 *** .01) r2 ///
				s(classfe mean sd r2 N, ///
				label("Class FE" "Mean" "SD" "\(R^2\)" "N")) ///
				label interaction(" $\times$ ") mtitles("\shortstack{Career \\ Satisfaction}") booktabs f noomitted nobaselevel

}



















